Skip to content

Commit 6e2fc11

Browse files
lukel97balazsorban44
authored andcommittedFeb 1, 2021
feat: Store user ID in sub claim of default JWT (#784)
This allows us to check if the user is signed in when using JWTs Part of #625
1 parent 6b1b861 commit 6e2fc11

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
 

‎src/server/lib/callback-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export default async (sessionToken, profile, providerAccount, options) => {
5252
if (useJwtSession) {
5353
try {
5454
session = await jwt.decode({ ...jwt, token: sessionToken })
55-
if (session && session.user) {
56-
user = await getUser(session.user.id)
55+
if (session && session.sub) {
56+
user = await getUser(session.sub)
5757
isSignedIn = !!user
5858
}
5959
} catch (e) {

‎src/server/routes/callback.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export default async (req, res, options, done) => {
8787
const defaultJwtPayload = {
8888
name: user.name,
8989
email: user.email,
90-
picture: user.image
90+
picture: user.image,
91+
sub: user.id.toString()
9192
}
9293
const jwtPayload = await callbacks.jwt(defaultJwtPayload, user, account, OAuthProfile, isNewUser)
9394

@@ -177,7 +178,8 @@ export default async (req, res, options, done) => {
177178
const defaultJwtPayload = {
178179
name: user.name,
179180
email: user.email,
180-
picture: user.image
181+
picture: user.image,
182+
sub: user.id.toString()
181183
}
182184
const jwtPayload = await callbacks.jwt(defaultJwtPayload, user, account, profile, isNewUser)
183185

0 commit comments

Comments
 (0)
Please sign in to comment.