feat: doc comments

This commit is contained in:
Catalin Pit
2024-01-11 11:53:52 +02:00
parent b09071ebc7
commit 13d23b6111
13 changed files with 262 additions and 79 deletions

View File

@ -0,0 +1,33 @@
import { getUserByApiToken } from '@documenso/lib/server-only/public-api/get-user-by-token';
export type Headers = {
headers: {
authorization: string;
};
};
export const authenticatedMiddleware = <T extends Headers>(fn: (args: T) => Promise<any>) => {
return async (args: T) => {
if (!args.headers.authorization) {
return {
status: 401,
body: {
message: 'Unauthorized access',
},
};
}
try {
await getUserByApiToken({ token: args.headers.authorization });
} catch (err) {
return {
status: 401,
body: {
message: 'Unauthorized access',
},
};
}
return fn(args);
};
};