mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: add authorization for api calls
This commit is contained in:
@ -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,
|
||||
}),
|
||||
|
||||
15
packages/lib/server-only/public-api/get-user-by-token.ts
Normal file
15
packages/lib/server-only/public-api/get-user-by-token.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user