2
0

feat: 📈 Inject user id for Sentry

This commit is contained in:
Baptiste Arnaud
2022-07-01 10:26:04 +02:00
parent a9a0aec375
commit cf6e8a21be
2 changed files with 9 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import { setUser } from '@sentry/nextjs'
import { User } from 'db'
import { NextApiRequest } from 'next'
import { getSession } from 'next-auth/react'
@ -7,5 +8,7 @@ export const getAuthenticatedUser = async (
): Promise<User | undefined> => {
const session = await getSession({ req })
if (!session?.user || !('id' in session.user)) return
const user = session.user as User
setUser({ id: user.id, email: user.email ?? undefined })
return session?.user as User
}