forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAuth.ts
More file actions
24 lines (17 loc) · 839 Bytes
/
Copy pathgetAuth.ts
File metadata and controls
24 lines (17 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { AuthObject } from '@clerk/backend';
import { stripPrivateDataFromObject } from '@clerk/backend/internal';
import { errorThrower } from '../utils';
import { noFetchFnCtxPassedInGetAuth } from '../utils/errors';
import { authenticateRequest } from './authenticateRequest';
import { loadOptions } from './loadOptions';
import type { LoaderOptions } from './types';
type GetAuthReturn = Promise<AuthObject>;
type GetAuthOptions = Pick<LoaderOptions, 'secretKey'>;
export async function getAuth(request: Request, opts?: GetAuthOptions): GetAuthReturn {
if (!request) {
return errorThrower.throw(noFetchFnCtxPassedInGetAuth);
}
const loadedOptions = loadOptions(request, opts);
const requestState = await authenticateRequest(request, loadedOptions);
return stripPrivateDataFromObject(requestState.toAuth());
}