Skip to content

Commit

Permalink
fix auto switch when adding account
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Dec 30, 2024
1 parent cf1d4fe commit 7524ecc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ function getCallbacks (req, res) {
const secret = process.env.NEXTAUTH_SECRET
const jwt = await encodeJWT({ token, secret })
const me = await prisma.user.findUnique({ where: { id: token.id } })
// we set multi_auth cookies on login/signup with only one user so the rest of the code doesn't
// have to consider the case where they aren't set yet because account switching wasn't used yet
setMultiAuthCookies(req, res, { ...me, jwt })
const hasMultiAuth = !!req.cookies['multi_auth.user-id']
if (!hasMultiAuth) {
// we set multi_auth cookies on login/signup with only one user so the rest of the code doesn't
// have to consider the case where they aren't set yet because account switching wasn't used yet
setMultiAuthCookies(req, res, { ...me, jwt })
}
}

return token
Expand Down

0 comments on commit 7524ecc

Please sign in to comment.