|
| 1 | +import type { AuthObject } from '@clerk/backend'; |
1 | 2 | import { constants } from '@clerk/backend/internal'; |
2 | 3 | import { isTruthy } from '@clerk/shared/underscore'; |
3 | 4 |
|
4 | 5 | import { withLogger } from '../utils/debugLogger'; |
5 | | -import { isNextWithUnstableServerActions } from '../utils/sdk-versions'; |
6 | 6 | import { getAuthDataFromRequest } from './data/getAuthDataFromRequest'; |
7 | 7 | import { getAuthAuthHeaderMissing } from './errors'; |
8 | | -import { detectClerkMiddleware, getHeader } from './headers-utils'; |
| 8 | +import { getHeader } from './headers-utils'; |
9 | 9 | import type { RequestLike } from './types'; |
10 | 10 | import { assertAuthStatus } from './utils'; |
11 | 11 |
|
12 | | -export const createAsyncGetAuth = ({ |
13 | | - debugLoggerName, |
| 12 | +export const createGetAuth = ({ |
14 | 13 | noAuthStatusMessage, |
15 | | -}: { |
16 | | - debugLoggerName: string; |
17 | | - noAuthStatusMessage: string; |
18 | | -}) => |
19 | | - withLogger(debugLoggerName, logger => { |
20 | | - return async (req: RequestLike, opts?: { secretKey?: string }) => { |
21 | | - if (isTruthy(getHeader(req, constants.Headers.EnableDebug))) { |
22 | | - logger.enable(); |
23 | | - } |
24 | | - |
25 | | - if (!detectClerkMiddleware(req)) { |
26 | | - // Keep the same behaviour for versions that may have issues with bundling `node:fs` |
27 | | - if (isNextWithUnstableServerActions) { |
28 | | - assertAuthStatus(req, noAuthStatusMessage); |
29 | | - } |
30 | | - |
31 | | - const missConfiguredMiddlewareLocation = await import('./keyless-node.js') |
32 | | - .then(m => m.suggestMiddlewareLocation()) |
33 | | - .catch(() => undefined); |
34 | | - |
35 | | - if (missConfiguredMiddlewareLocation) { |
36 | | - throw new Error(missConfiguredMiddlewareLocation); |
37 | | - } |
38 | | - |
39 | | - // still throw there is no suggested move location |
40 | | - assertAuthStatus(req, noAuthStatusMessage); |
41 | | - } |
42 | | - |
43 | | - return getAuthDataFromRequest(req, { ...opts, logger }); |
44 | | - }; |
45 | | - }); |
46 | | - |
47 | | -export const createSyncGetAuth = ({ |
48 | 14 | debugLoggerName, |
49 | | - noAuthStatusMessage, |
50 | 15 | }: { |
51 | 16 | debugLoggerName: string; |
52 | 17 | noAuthStatusMessage: string; |
53 | 18 | }) => |
54 | 19 | withLogger(debugLoggerName, logger => { |
55 | | - return (req: RequestLike, opts?: { secretKey?: string }) => { |
| 20 | + return (req: RequestLike, opts?: { secretKey?: string }): AuthObject => { |
56 | 21 | if (isTruthy(getHeader(req, constants.Headers.EnableDebug))) { |
57 | 22 | logger.enable(); |
58 | 23 | } |
59 | 24 |
|
60 | 25 | assertAuthStatus(req, noAuthStatusMessage); |
| 26 | + |
61 | 27 | return getAuthDataFromRequest(req, { ...opts, logger }); |
62 | 28 | }; |
63 | 29 | }); |
@@ -141,7 +107,7 @@ export const createSyncGetAuth = ({ |
141 | 107 | * } |
142 | 108 | * ``` |
143 | 109 | */ |
144 | | -export const getAuth = createSyncGetAuth({ |
| 110 | +export const getAuth = createGetAuth({ |
145 | 111 | debugLoggerName: 'getAuth()', |
146 | 112 | noAuthStatusMessage: getAuthAuthHeaderMissing(), |
147 | 113 | }); |
0 commit comments