Fix inconsistent session cookie name

This commit is contained in:
ekzyis 2023-12-21 10:08:23 +01:00
parent 09b468660b
commit 74304e2f75
3 changed files with 13 additions and 2 deletions

View File

@ -20,7 +20,7 @@ const multiAuthMiddleware = (request) => {
const cookiePointerName = 'multi_auth.user-id'
const hasCookiePointer = request.cookies?.has(cookiePointerName)
// is there a session?
const sessionCookieName = '__Secure-next-auth.session-token'
const sessionCookieName = 'next-auth.session-token'
const hasSession = request.cookies?.has(sessionCookieName)
if (!hasCookiePointer || !hasSession) {

View File

@ -248,6 +248,17 @@ export const getAuthOptions = (req, res) => ({
signIn: '/login',
verifyRequest: '/email',
error: '/auth/error'
},
cookies: {
sessionToken: {
name: 'next-auth.session-token',
options: {
httpOnly: true,
sameSite: 'lax',
path: '/',
secure: true
}
}
}
})

View File

@ -11,7 +11,7 @@ export default (req, res) => {
const cookiePointerName = 'multi_auth.user-id'
const userId = req.cookies[cookiePointerName]
// is there a session?
const sessionCookieName = '__Secure-next-auth.session-token'
const sessionCookieName = 'next-auth.session-token'
const sessionJWT = req.cookies[sessionCookieName]
if (!userId || !sessionJWT) {