Skip to content

Commit

Permalink
feat: check existence of session
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Jul 24, 2023
1 parent a5f0611 commit d0b9b3e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/lib/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const nextAuthOptions: NextAuthOptions = {
return {} as Session
}

//? Verify that the user still exists
//* Verify that the user still exists
const userExists = await prisma.user.findUnique({
where: {
id: token.id,
Expand All @@ -116,6 +116,23 @@ export const nextAuthOptions: NextAuthOptions = {
return {} as Session
}

//* Verify that the session still exists
if (!token.uuid || typeof token.uuid !== "string") {
logger.debug("Missing token uuid")
return {} as Session
}

const sessionExists = await prisma.session.findUnique({
where: {
sessionToken: token.uuid,
},
})
if (!sessionExists) {
logger.debug("Session not found", token.uuid)
return {} as Session
}

//* Fill session with user data
let username
if (user && "username" in user) {
username = user.username
Expand Down

0 comments on commit d0b9b3e

Please sign in to comment.