mirror of
https://github.com/documenso/documenso.git
synced 2025-11-24 05:32:12 +10:00
zapier webhooks
This commit is contained in:
16
packages/lib/server-only/webhooks/zapier/validateApiToken.ts
Normal file
16
packages/lib/server-only/webhooks/zapier/validateApiToken.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { getUserByApiToken } from '../../public-api/get-user-by-token';
|
||||
|
||||
type ValidateApiTokenOptions = {
|
||||
authorization: string | undefined;
|
||||
};
|
||||
|
||||
export const validateApiToken = async ({ authorization }: ValidateApiTokenOptions) => {
|
||||
try {
|
||||
// Support for both "Authorization: Bearer api_xxx" and "Authorization: api_xxx"
|
||||
const [token] = (authorization || '').split('Bearer ').filter((s) => s.length > 0);
|
||||
|
||||
return await getUserByApiToken({ token });
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to validate API token`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user