Skip to content

Commit 69e9760

Browse files
committed
chore: reuse token type utility from backend
1 parent 29d7bf9 commit 69e9760

File tree

4 files changed

+5
-20
lines changed

4 files changed

+5
-20
lines changed

packages/nextjs/src/server/clerkMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
constants,
1313
createClerkRequest,
1414
createRedirect,
15+
isTokenTypeAccepted,
1516
signedOutAuthObject,
1617
unauthenticatedMachineObject,
1718
} from '@clerk/backend/internal';
@@ -47,7 +48,6 @@ import {
4748
assertKey,
4849
decorateRequest,
4950
handleMultiDomainAndProxy,
50-
isTokenTypeAccepted,
5151
redirectAdapter,
5252
setRequestHeadersOnNextResponse,
5353
} from './utils';

packages/nextjs/src/server/data/getAuthDataFromRequest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
constants,
77
getMachineTokenType,
88
isMachineToken,
9+
isTokenTypeAccepted,
910
signedInAuthObject,
1011
signedOutAuthObject,
1112
unauthenticatedMachineObject,
@@ -17,7 +18,7 @@ import type { LoggerNoCommit } from '../../utils/debugLogger';
1718
import { API_URL, API_VERSION, PUBLISHABLE_KEY, SECRET_KEY } from '../constants';
1819
import { getAuthKeyFromRequest, getHeader } from '../headers-utils';
1920
import type { RequestLike } from '../types';
20-
import { assertTokenSignature, decryptClerkRequestData, isTokenTypeAccepted } from '../utils';
21+
import { assertTokenSignature, decryptClerkRequestData } from '../utils';
2122

2223
export type GetAuthDataFromRequestOptions = {
2324
secretKey?: string;

packages/nextjs/src/server/protect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { AuthObject } from '@clerk/backend';
22
import type { AuthenticatedMachineObject, RedirectFun, SignedInAuthObject, TokenType } from '@clerk/backend/internal';
3-
import { constants } from '@clerk/backend/internal';
3+
import { constants, isTokenTypeAccepted } from '@clerk/backend/internal';
44
import type {
55
CheckAuthorizationFromSessionClaims,
66
CheckAuthorizationParamsFromSessionClaims,
@@ -10,7 +10,6 @@ import type {
1010
} from '@clerk/types';
1111

1212
import { constants as nextConstants } from '../constants';
13-
import { isTokenTypeAccepted } from '../server/utils';
1413
import { isNextFetcher } from './nextFetcher';
1514
import type { InferAuthObjectFromToken, InferAuthObjectFromTokenArray } from './types';
1615

packages/nextjs/src/server/utils.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AuthenticateRequestOptions, ClerkRequest, RequestState, TokenType } from '@clerk/backend/internal';
1+
import type { AuthenticateRequestOptions, ClerkRequest, RequestState } from '@clerk/backend/internal';
22
import { constants } from '@clerk/backend/internal';
33
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
44
import { logger } from '@clerk/shared/logger';
@@ -259,18 +259,3 @@ function decryptData(data: string, key: string) {
259259
const encoded = decryptedBytes.toString(Utf8);
260260
return JSON.parse(encoded);
261261
}
262-
263-
/**
264-
* Check if a token type is accepted given a requested token type.
265-
*/
266-
export const isTokenTypeAccepted = (
267-
tokenType: TokenType,
268-
acceptsToken: NonNullable<AuthenticateRequestOptions['acceptsToken']>,
269-
): boolean => {
270-
if (acceptsToken === 'any') {
271-
return true;
272-
}
273-
274-
const tokenTypes = Array.isArray(acceptsToken) ? acceptsToken : [acceptsToken];
275-
return tokenTypes.includes(tokenType);
276-
};

0 commit comments

Comments
 (0)