2
0

feat(user): Revokable API tokens

This commit is contained in:
Baptiste Arnaud
2022-06-03 13:20:19 +02:00
parent e5d7f1d1ce
commit a0929c492b
20 changed files with 472 additions and 43 deletions

View File

@ -13,7 +13,9 @@ const authenticateByToken = async (
apiToken?: string
): Promise<User | undefined> => {
if (!apiToken) return
return (await prisma.user.findFirst({ where: { apiToken } })) as User
return (await prisma.user.findFirst({
where: { apiTokens: { some: { token: apiToken } } },
})) as User
}
const extractBearerToken = (req: NextApiRequest) =>