diff --git a/.changeset/lazy-cows-shake.md b/.changeset/lazy-cows-shake.md new file mode 100644 index 00000000..096b82e9 --- /dev/null +++ b/.changeset/lazy-cows-shake.md @@ -0,0 +1,5 @@ +--- +'@supabase/auth-helpers-shared': patch +--- + +Add jose for it's cross platform base64url decode support diff --git a/.changeset/plenty-seas-build.md b/.changeset/plenty-seas-build.md new file mode 100644 index 00000000..33812db4 --- /dev/null +++ b/.changeset/plenty-seas-build.md @@ -0,0 +1,5 @@ +--- +'@supabase/auth-helpers-shared': patch +--- + +Remove js-base64 as its buffer check was causing issues for Vercel Edge Runtime diff --git a/packages/shared/package.json b/packages/shared/package.json index 7eb91b3a..f00fe69d 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -32,15 +32,15 @@ "devDependencies": { "@supabase/supabase-js": "2.19.0", "@types/cookie": "^0.5.1", + "cookie": "^0.5.0", "next": "^12.1.5", "react": ">=17.0.2 <18.0.0 || >=18.0.0-0 <19.0.0", "react-dom": "^17.0.2 || ^18.0.0-0", "tsconfig": "workspace:*", - "tsup": "^6.5.0", - "cookie": "^0.5.0" + "tsup": "^6.5.0" }, "dependencies": { - "js-base64": "^3.7.5" + "jose": "^4.14.3" }, "peerDependencies": { "@supabase/supabase-js": "^2.19.0" diff --git a/packages/shared/src/utils/cookies.ts b/packages/shared/src/utils/cookies.ts index deee0180..d8f7d279 100644 --- a/packages/shared/src/utils/cookies.ts +++ b/packages/shared/src/utils/cookies.ts @@ -1,6 +1,6 @@ import { Session } from '@supabase/supabase-js'; import { parse, serialize } from 'cookie'; -import { fromBase64 } from 'js-base64'; +import { base64url } from 'jose'; export { parse as parseCookies, serialize as serializeCookie }; @@ -48,9 +48,10 @@ export function parseSupabaseCookie( } const [_header, payloadStr, _signature] = session[0].split('.'); - const payload = fromBase64(payloadStr); + const payload = base64url.decode(payloadStr); + const decoder = new TextDecoder(); - const { exp, sub, ...user } = JSON.parse(payload); + const { exp, sub, ...user } = JSON.parse(decoder.decode(payload)); return { expires_at: exp, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0d1e8b09..056c0ec0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -379,9 +379,9 @@ importers: packages/shared: dependencies: - js-base64: - specifier: ^3.7.5 - version: 3.7.5 + jose: + specifier: ^4.14.3 + version: 4.14.3 devDependencies: '@supabase/supabase-js': specifier: 2.19.0 @@ -7488,15 +7488,15 @@ packages: engines: {node: '>=0.10.0'} dev: true + /jose@4.14.3: + resolution: {integrity: sha512-YPM9Q+dmsna4CGWNn5+oHFsuXJdxvKAOVoNjpe2nje3odSoX5Xz4s71rP50vM8uUKJyQtMnEGPmbVCVR+G4W5g==} + dev: false + /joycon@3.1.1: resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} engines: {node: '>=10'} dev: true - /js-base64@3.7.5: - resolution: {integrity: sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==} - dev: false - /js-sdsl@4.1.5: resolution: {integrity: sha512-08bOAKweV2NUC1wqTtf3qZlnpOX/R2DU9ikpjOHs0H+ibQv3zpncVQg6um4uYtRtrwIX8M4Nh3ytK4HGlYAq7Q==}