2
0

♻️ (viewer) Remove barrel exports and flatten folder arch

This commit is contained in:
Baptiste Arnaud
2023-03-15 12:21:52 +01:00
parent 44d7a0bcb8
commit f3af07b7ff
113 changed files with 398 additions and 426 deletions

View File

@ -0,0 +1,19 @@
import { User } from '@typebot.io/prisma'
import { NextApiRequest } from 'next'
import prisma from '@/lib/prisma'
export const authenticateUser = async (
req: NextApiRequest
): Promise<User | undefined> => authenticateByToken(extractBearerToken(req))
const authenticateByToken = async (
apiToken?: string
): Promise<User | undefined> => {
if (!apiToken) return
return (await prisma.user.findFirst({
where: { apiTokens: { some: { token: apiToken } } },
})) as User
}
const extractBearerToken = (req: NextApiRequest) =>
req.headers['authorization']?.slice(7)