Skip to content

Commit

Permalink
🔧 properly update the token details, otherwise invalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Sep 29, 2024
1 parent edb3042 commit d8c4d1a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ const get = async ({ user }: { user: User }, event: H3Event) => {

const me = defineEventHandler(async (event) => {
const { user } = await requireUserSession(event)
const dbUser = await usePrisma(event).user.update({ where: { id: user.id }, data: { updatedAt: new Date() } }) as unknown as User
dbUser.hash = user.hash
await replaceUserSession(event, { user: dbUser })
return metapi().render(dbUser)
try {
const dbUser = await usePrisma(event).user.update({ where: { id: user.id }, data: { updatedAt: new Date() } }) as unknown as User
dbUser.hash = user.hash
await usePrisma(event).token.update({ where: { hash: user.hash, userId: user.id }, data: { updatedAt: new Date() } })
await replaceUserSession(event, { user: dbUser })
return metapi().render(dbUser)
}
// eslint-disable-next-line unused-imports/no-unused-vars
catch (e) {
console.log('why isnt this working')
await clearUserSession(event)
}
})

const logout = defineEventHandler(async (event) => {
Expand Down

0 comments on commit d8c4d1a

Please sign in to comment.