feat: add authorization for api calls

This commit is contained in:
Catalin Pit
2023-11-30 14:39:31 +02:00
parent 76800674ee
commit 6be4b7ae90
4 changed files with 107 additions and 7 deletions

View File

@ -3,11 +3,15 @@ import { prisma } from '@documenso/prisma';
type GetDocumentsProps = {
page: number;
perPage: number;
userId: number;
};
export const getDocuments = async ({ page = 1, perPage = 10 }: GetDocumentsProps) => {
export const getDocuments = async ({ page = 1, perPage = 10, userId }: GetDocumentsProps) => {
const [documents, count] = await Promise.all([
await prisma.document.findMany({
where: {
userId,
},
take: perPage,
skip: Math.max(page - 1, 0) * perPage,
}),

View File

@ -0,0 +1,15 @@
import { prisma } from '@documenso/prisma';
export const checkUserFromToken = async ({ token }: { token: string }) => {
const user = await prisma.user.findFirstOrThrow({
where: {
ApiToken: {
some: {
token: token,
},
},
},
});
return user;
};