Skip to content

Commit

Permalink
Fix user serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Aug 25, 2023
1 parent 84a6231 commit 1a9e93b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/server/util/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const verifyLogin = async (
isAdmin: checkAdmin(iamGroups),
}

await User.findByIdAndUpdate(user.id, { ...user })
await User.findOneAndUpdate({ username }, { ...user }, { upsert: true })

done(null, user)
}
Expand All @@ -80,14 +80,17 @@ const setupAuthentication = async () => {
const client = await getClient()

passport.serializeUser((user, done) => {
const { id, iamGroups, isAdmin } = user as UserType
const { username, iamGroups, isAdmin } = user as UserType

return done(null, { id, iamGroups, isAdmin })
return done(null, { username, iamGroups, isAdmin })
})

passport.deserializeUser(
async ({ id, iamGroups }: { id: string; iamGroups: string[] }, done) => {
const user = await User.findById(id)
async (
{ username, iamGroups }: { username: string; iamGroups: string[] },
done
) => {
const user = await User.findOne({ username })

if (!user) return done(new Error('User not found'))

Expand Down

0 comments on commit 1a9e93b

Please sign in to comment.