Skip to content

Commit

Permalink
chore: add jose to .next branch (#526)
Browse files Browse the repository at this point in the history
* Add jose for it's base64url decode support

* Remove js-base64 becuase buffer check Vercel issue
  • Loading branch information
silentworks committed Apr 28, 2023
1 parent 376e03c commit 56db807
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-cows-shake.md
@@ -0,0 +1,5 @@
---
'@supabase/auth-helpers-shared': patch
---

Add jose for it's cross platform base64url decode support
5 changes: 5 additions & 0 deletions .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
6 changes: 3 additions & 3 deletions packages/shared/package.json
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions 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 };

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56db807

Please sign in to comment.