correction nextauth

This commit is contained in:
alma 2026-01-04 01:40:25 +01:00
parent 6321d1623f
commit cdb93a30a0

View File

@ -281,7 +281,7 @@ export const authOptions: NextAuthOptions = {
return refreshedToken;
},
async session({ session, token }) {
// If session was invalidated or tokens are missing, throw error to trigger sign out
// If session was invalidated or tokens are missing, return null to sign out
if (token.error === "SessionNotActive" ||
token.error === "NoRefreshToken" ||
!token.accessToken ||
@ -292,9 +292,11 @@ export const authOptions: NextAuthOptions = {
hasRefreshToken: !!token.refreshToken
});
// Throw error to make NextAuth treat user as unauthenticated
// Return null to make NextAuth treat user as unauthenticated
// This will trigger automatic redirect to sign-in page
throw new Error(token.error || "SessionInvalidated");
// The client-side code will detect session invalidation by checking for
// session cookie existence when status is unauthenticated
return null as any;
}
// For other errors, throw to trigger error handling