mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
chore: implemented feedback + a small refactoring
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export const checkUserFromToken = async ({ token }: { token: string }) => {
|
||||
const user = await prisma.user.findFirstOrThrow({
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
ApiToken: {
|
||||
some: {
|
||||
@ -9,7 +9,20 @@ export const checkUserFromToken = async ({ token }: { token: string }) => {
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
ApiToken: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error('Token not found');
|
||||
}
|
||||
|
||||
const tokenObject = user.ApiToken.find((apiToken) => apiToken.token === token);
|
||||
|
||||
if (!tokenObject || new Date(tokenObject.expires) < new Date()) {
|
||||
throw new Error('The API token has expired');
|
||||
}
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user