Skip to content

Commit

Permalink
Merge pull request #128 from rmarscher/lucia-enable-tokens-check
Browse files Browse the repository at this point in the history
[Lucia] Fix to setting cookies
  • Loading branch information
timothymiller authored Dec 21, 2023
2 parents 90a537e + 7ecc3f7 commit 325b5e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/auth/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const signInWithEmail = async (
await updatePassword(ctx, email, password)
}
const session = await createSession(ctx.auth, authMethod.userId)
if (setCookie) {
if (!ctx.enableTokens && setCookie) {
const cookie = ctx.auth.createSessionCookie(session.id)
setCookie(cookie.serialize())
}
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const signInWithAppleIdTokenHandler =
idTokenClaims: payload,
})
const session = await createSession(ctx.auth, user.id)
if (ctx.enableTokens && ctx.setCookie) {
if (!ctx.enableTokens && ctx.setCookie) {
ctx.setCookie(ctx.auth.createSessionCookie(session.id).serialize())
}
return { session }
Expand Down Expand Up @@ -247,7 +247,7 @@ const signInWithEmailCodeHandler =
console.log('calling update passing and invalidate sessions')
await ctx.auth.invalidateUserSessions(res.session?.userId)
const session = await createSession(ctx.auth, res.session?.userId)
if (ctx.enableTokens && ctx.setCookie) {
if (!ctx.enableTokens && ctx.setCookie) {
ctx.setCookie(ctx.auth.createSessionCookie(session.id).serialize())
}
res.session = session
Expand Down Expand Up @@ -342,7 +342,7 @@ export const userRouter = router({
email: input.email,
})
const session = await createSession(ctx.auth, user.id)
if (ctx.enableTokens && ctx.setCookie) {
if (!ctx.enableTokens && ctx.setCookie) {
ctx.setCookie(ctx.auth.createSessionCookie(session.id).serialize())
}
return { session }
Expand Down

0 comments on commit 325b5e5

Please sign in to comment.