Skip to content

Commit

Permalink
Fix 500 if multi_auth cookie missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Nov 11, 2024
1 parent 5e08e03 commit 931cb64
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pages/api/signout.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default (req, res) => {
cookies.push(cookie.serialize(`multi_auth.${userId}`, '', { ...cookieOptions, expires: 0, maxAge: 0 }))

// update multi_auth cookie and check if there are more accounts available
const oldMultiAuth = b64Decode(req.cookies.multi_auth)
const newMultiAuth = oldMultiAuth.filter(({ id }) => id !== Number(userId))
if (newMultiAuth.length === 0) {
const oldMultiAuth = req.cookies.multi_auth ? b64Decode(req.cookies.multi_auth) : undefined
const newMultiAuth = oldMultiAuth?.filter(({ id }) => id !== Number(userId))
if (!oldMultiAuth || newMultiAuth?.length === 0) {
// no next account available. cleanup: remove multi_auth + pointer cookie
cookies.push(cookie.serialize('multi_auth', '', { ...cookieOptions, httpOnly: false, expires: 0, maxAge: 0 }))
cookies.push(cookie.serialize('multi_auth.user-id', '', { ...cookieOptions, httpOnly: false, expires: 0, maxAge: 0 }))
Expand Down

0 comments on commit 931cb64

Please sign in to comment.