Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Buffer causing runtime errors #32

Open
BenSampo opened this issue Oct 22, 2024 · 1 comment
Open

Use of Buffer causing runtime errors #32

BenSampo opened this issue Oct 22, 2024 · 1 comment

Comments

@BenSampo
Copy link

The Buffer.from method is used in utils to decode the token. Buffer isn't available outside of node environments (e.g. within the browser) and is causing runtime errors (ReferenceError: Buffer is not defined).

const decodedTokenData = Buffer.from(tokenParts[1] || "", "base64").toString();

For reference, I'm using the obtainAccessToken on the SaleorExternalAuth class which is in turn calling this util method. I'm trying to implement an external OIDC flow using Apollo - which isn't in the docs and have been loosely following this:
https://github.com/saleor/auth-sdk?tab=readme-ov-file#nextjs-pages-router-with-openid-connect

@Shaokun-X
Copy link

Shaokun-X commented Oct 27, 2024

I had the same issue, my current workaround is polyfilling the Buffer class as described in this issue vitejs/vite#2785:

$ npm i buffer
// in the entry file of your app

// fix the buffer bug in @saleor/auth-sdk
import { Buffer } from 'buffer';
globalThis.Buffer = Buffer;

For bundlers other than vite the workaround should be similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants