Skip to content

Commit a8ae658

Browse files
committed
fix: correctly decode base64 supabase secret and specify HS256 algorithm with precise multi-key kid header
1 parent 855ae07 commit a8ae658

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/auth.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ const config: NextAuthConfig = {
2525
}
2626
}
2727

28-
const secret = process.env.SUPABASE_JWT_SECRET
29-
if (secret && token.id) {
28+
const secretString = process.env.SUPABASE_JWT_SECRET
29+
if (secretString && token.id) {
30+
// Must strictly decode base64 into raw bytes for Supabase HS256!
31+
const secretBuffer = Buffer.from(secretString, "base64")
3032
token.supabaseAccessToken = jwt.sign(
3133
{
3234
aud: "authenticated",
@@ -35,7 +37,13 @@ const config: NextAuthConfig = {
3537
email: token.email,
3638
role: "authenticated",
3739
},
38-
secret,
40+
secretBuffer,
41+
{
42+
header: {
43+
alg: "HS256",
44+
kid: "7F438B89-1B14-4807-95B5-AAB76A6A0051",
45+
},
46+
},
3947
)
4048
}
4149
return token

0 commit comments

Comments
 (0)