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'
|
2022-08-08 08:21:36 +02:00
|
|
|
|
2022-09-17 16:37:33 +02:00
|
|
|
export const mockedUser: User = {
|
|
|
|
id: 'userId',
|
|
|
|
name: 'John Doe',
|
|
|
|
email: 'user@email.com',
|
2022-08-08 08:21:36 +02:00
|
|
|
company: null,
|
|
|
|
createdAt: new Date(),
|
|
|
|
emailVerified: null,
|
|
|
|
graphNavigation: 'TRACKPAD',
|
|
|
|
image: 'https://avatars.githubusercontent.com/u/16015833?v=4',
|
|
|
|
lastActivityAt: new Date(),
|
|
|
|
onboardingCategories: [],
|
|
|
|
updatedAt: new Date(),
|
|
|
|
}
|
2022-02-24 11:13:19 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|