|
1 | 1 | import type { AuthenticateRequestOptions, GetAuthFn } from '@clerk/backend/internal'; |
2 | 2 | import { getAuthObjectForAcceptedToken } from '@clerk/backend/internal'; |
| 3 | +import { getContext } from '@tanstack/react-start/server'; |
3 | 4 |
|
4 | 5 | import { errorThrower } from '../utils'; |
5 | 6 | import { noFetchFnCtxPassedInGetAuth } from '../utils/errors'; |
6 | | -import { authenticateRequest } from './authenticateRequest'; |
7 | | -import { loadOptions } from './loadOptions'; |
8 | | -import type { LoaderOptions } from './types'; |
9 | 7 |
|
10 | | -type GetAuthOptions = { acceptsToken?: AuthenticateRequestOptions['acceptsToken'] } & Pick<LoaderOptions, 'secretKey'>; |
| 8 | +type GetAuthOptions = { acceptsToken?: AuthenticateRequestOptions['acceptsToken'] }; |
11 | 9 |
|
12 | | -export const getAuth: GetAuthFn<Request, true> = (async (request: Request, opts?: GetAuthOptions) => { |
| 10 | +export const getAuth: GetAuthFn<Request> = ((request: Request, opts?: GetAuthOptions) => { |
13 | 11 | if (!request) { |
14 | 12 | return errorThrower.throw(noFetchFnCtxPassedInGetAuth); |
15 | 13 | } |
16 | 14 |
|
17 | | - const { acceptsToken, ...restOptions } = opts || {}; |
| 15 | + const authObjectFn = getContext('auth'); |
18 | 16 |
|
19 | | - const loadedOptions = loadOptions(request, restOptions); |
20 | | - |
21 | | - const requestState = await authenticateRequest(request, { |
22 | | - ...loadedOptions, |
23 | | - acceptsToken: 'any', |
24 | | - }); |
25 | | - |
26 | | - const authObject = requestState.toAuth(); |
27 | | - |
28 | | - return getAuthObjectForAcceptedToken({ authObject, acceptsToken }); |
29 | | -}) as GetAuthFn<Request, true>; |
| 17 | + return getAuthObjectForAcceptedToken({ authObject: authObjectFn(), acceptsToken: opts?.acceptsToken }); |
| 18 | +}) as GetAuthFn<Request>; |
0 commit comments