Skip to content

Commit

Permalink
fix: rename session to cookie to make more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
BibiSebi committed Jul 2, 2024
1 parent 0c9e25d commit 7e1a82a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/session-adapters/cookieAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ export const cookieAdapter: Adapter = {
return verifyData(clientSecret)(cookie) as object
},
setItem: ({ req, res, key, value }) => {
const currentSession = cookieAdapter.getItem({ req, res, key })
const cookieValue = cookieAdapter.getItem({ req, res, key })

// TODO: Improve readability
// TODO: improve checking as user might select their own key and not sb.auth
const isSession = key === 'sb.auth'
const data = isSession
? {
sessions: currentSession ? [currentSession, value] : [value],
}
: value
const isCallbackCookie = key === 'auth.sb.callback'
const cookieWithAllSessions = {
sessions: cookieValue ? [cookieValue, value] : [value],
}

const data = isCallbackCookie ? value : cookieWithAllSessions

const signedData = jwt.sign({ data }, clientSecret)
setCookie(res, key, signedData)
Expand Down

0 comments on commit 7e1a82a

Please sign in to comment.