2022-07-01 10:26:04 +02:00
|
|
|
import { setUser } from '@sentry/nextjs'
|
2022-02-24 11:13:19 +01:00
|
|
|
import { User } from 'db'
|
|
|
|
import { NextApiRequest } from 'next'
|
|
|
|
import { getSession } from 'next-auth/react'
|
|
|
|
|
|
|
|
export const getAuthenticatedUser = async (
|
|
|
|
req: NextApiRequest
|
|
|
|
): Promise<User | undefined> => {
|
|
|
|
const session = await getSession({ req })
|
2022-03-04 17:21:01 +01:00
|
|
|
if (!session?.user || !('id' in session.user)) return
|
2022-07-01 10:26:04 +02:00
|
|
|
const user = session.user as User
|
|
|
|
setUser({ id: user.id, email: user.email ?? undefined })
|
2022-02-24 17:44:23 +01:00
|
|
|
return session?.user as User
|
2022-02-24 11:13:19 +01:00
|
|
|
}
|