mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
chore: refactor code
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { getUserByApiToken } from '../../public-api/get-user-by-token';
|
||||
import { getApiTokenByToken } from '../../public-api/get-api-token-by-token';
|
||||
|
||||
type ValidateApiTokenOptions = {
|
||||
authorization: string | undefined;
|
||||
@ -9,7 +9,11 @@ export const validateApiToken = async ({ authorization }: ValidateApiTokenOption
|
||||
// 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 });
|
||||
if (!token) {
|
||||
throw new Error('Missing API token');
|
||||
}
|
||||
|
||||
return await getApiTokenByToken({ token });
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to validate API token`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user