feat: Implement guest menu in the common header for unauthenticated users and enhance JWT session handling for user profile updates.
This commit is contained in:
@@ -145,7 +145,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
|
||||
return true;
|
||||
},
|
||||
|
||||
async jwt({ token, user }) {
|
||||
async jwt({ token, user, trigger, session: updateData }) {
|
||||
if (user) {
|
||||
token.id = user.id;
|
||||
token.name = user.name;
|
||||
@@ -158,6 +158,12 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
|
||||
token.accessTokenIssuedAt = Date.now();
|
||||
}
|
||||
|
||||
// Handle session updates from client-side updateSession() calls
|
||||
if (trigger === "update" && updateData?.user) {
|
||||
if (updateData.user.name) token.name = updateData.user.name;
|
||||
if (updateData.user.image !== undefined) token.picture = updateData.user.image;
|
||||
}
|
||||
|
||||
// Auto-refresh the access token if it's about to expire (refresh 2 minutes before expiry)
|
||||
// Backend JWT_ACCESS_EXPIRATION=15m, so refresh at ~13 minutes
|
||||
const ACCESS_TOKEN_MAX_AGE = 13 * 60 * 1000; // 13 minutes in ms
|
||||
|
||||
Reference in New Issue
Block a user