📝 Introduce auto generate API doc
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
import { setUser } from '@sentry/nextjs'
|
||||
import { User } from 'db'
|
||||
import { NextApiRequest } from 'next'
|
||||
@@ -6,9 +7,24 @@ import { getSession } from 'next-auth/react'
|
||||
export const getAuthenticatedUser = async (
|
||||
req: NextApiRequest
|
||||
): Promise<User | undefined> => {
|
||||
const bearerToken = extractBearerToken(req)
|
||||
if (bearerToken) return authenticateByToken(bearerToken)
|
||||
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
|
||||
}
|
||||
|
||||
const authenticateByToken = async (
|
||||
apiToken: string
|
||||
): Promise<User | undefined> => {
|
||||
console.log(window)
|
||||
if (typeof window !== 'undefined') return
|
||||
return (await prisma.user.findFirst({
|
||||
where: { apiTokens: { some: { token: apiToken } } },
|
||||
})) as User
|
||||
}
|
||||
|
||||
const extractBearerToken = (req: NextApiRequest) =>
|
||||
req.headers['authorization']?.slice(7)
|
||||
|
||||
1
apps/builder/src/features/auth/api/index.ts
Normal file
1
apps/builder/src/features/auth/api/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './getAuthenticatedUser'
|
||||
@@ -1,3 +1,2 @@
|
||||
export { SignInPage } from './components/SignInPage'
|
||||
export { getAuthenticatedUser } from './api/getAuthenticatedUser'
|
||||
export { mockedUser } from './constants'
|
||||
|
||||
@@ -10,6 +10,8 @@ export const deleteResultsProcedure = authenticatedProcedure
|
||||
method: 'DELETE',
|
||||
path: '/typebots/{typebotId}/results',
|
||||
protect: true,
|
||||
summary: 'Delete results',
|
||||
tags: ['Results'],
|
||||
},
|
||||
})
|
||||
.input(
|
||||
|
||||
@@ -10,6 +10,8 @@ export const getResultLogsProcedure = authenticatedProcedure
|
||||
method: 'GET',
|
||||
path: '/typebots/{typebotId}/results/{resultId}/logs',
|
||||
protect: true,
|
||||
summary: 'List result logs',
|
||||
tags: ['Results'],
|
||||
},
|
||||
})
|
||||
.input(
|
||||
|
||||
@@ -13,6 +13,8 @@ export const getResultsProcedure = authenticatedProcedure
|
||||
method: 'GET',
|
||||
path: '/typebots/{typebotId}/results',
|
||||
protect: true,
|
||||
summary: 'List results',
|
||||
tags: ['Results'],
|
||||
},
|
||||
})
|
||||
.input(
|
||||
|
||||
Reference in New Issue
Block a user