♻️ (builder) Change to features-centric folder structure
This commit is contained in:
committed by
Baptiste Arnaud
parent
3686465a85
commit
643571fe7d
14
apps/builder/src/features/auth/api/getAuthenticatedUser.ts
Normal file
14
apps/builder/src/features/auth/api/getAuthenticatedUser.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { setUser } from '@sentry/nextjs'
|
||||
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 })
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user