Skip to content

Commit

Permalink
Fix inconsistent session cookie name
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Dec 21, 2023
1 parent c163864 commit bfc4955
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
})

Expand Down
2 changes: 1 addition & 1 deletion pages/api/signout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bfc4955

Please sign in to comment.