Skip to content

Commit f56b6b9

Browse files
authored
chore(nextjs)!: Throw when missing encryption key (#7360)
1 parent 30ad5f8 commit f56b6b9

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.changeset/moody-peaches-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/nextjs': major
3+
---
4+
5+
Throw an error when an encryption key is missing when passing a secret key at runtime `clerkMiddleware()`. To migrate, ensure your application specifies a `CLERK_ENCRYPTION_KEY` environment variable when passing `secretKey` as a runtime option.

packages/nextjs/src/server/errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ export const authSignatureInvalid = `Clerk: Unable to verify request, this usual
3434
export const encryptionKeyInvalid = `Clerk: Unable to decrypt request data, this usually means the encryption key is invalid. Ensure the encryption key is properly set. For more information, see: https://clerk.com/docs/reference/nextjs/clerk-middleware#dynamic-keys. (code=encryption_key_invalid)`;
3535

3636
export const encryptionKeyInvalidDev = `Clerk: Unable to decrypt request data.\n\nRefresh the page if your .env file was just updated. If the issue persists, ensure the encryption key is valid and properly set.\n\nFor more information, see: https://clerk.com/docs/reference/nextjs/clerk-middleware#dynamic-keys. (code=encryption_key_invalid)`;
37+
export const encryptionKeyMissing =
38+
'Clerk: Missing `CLERK_ENCRYPTION_KEY`. Required for propagating `secretKey` middleware option. See docs: https://clerk.com/docs/references/nextjs/clerk-middleware#dynamic-keys. (code=encryption_key_missing)';

packages/nextjs/src/server/utils.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { AuthObject } from '@clerk/backend';
22
import type { AuthenticateRequestOptions, ClerkRequest, RequestState } from '@clerk/backend/internal';
33
import { constants } from '@clerk/backend/internal';
44
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
5-
import { logger } from '@clerk/shared/logger';
65
import { isHttpOrHttps } from '@clerk/shared/proxy';
76
import { handleValueOrFn, isProductionEnvironment } from '@clerk/shared/utils';
87
import { NextResponse } from 'next/server';
@@ -15,6 +14,7 @@ import {
1514
authSignatureInvalid,
1615
encryptionKeyInvalid,
1716
encryptionKeyInvalidDev,
17+
encryptionKeyMissing,
1818
missingDomainAndProxy,
1919
missingSignInUrlInDev,
2020
} from './errors';
@@ -200,12 +200,7 @@ export function encryptClerkRequestData(
200200
}
201201

202202
if (requestData.secretKey && !ENCRYPTION_KEY) {
203-
// TODO SDK-1833: change this to an error in the next major version of `@clerk/nextjs`
204-
logger.warnOnce(
205-
'Clerk: Missing `CLERK_ENCRYPTION_KEY`. Required for propagating `secretKey` middleware option. See docs: https://clerk.com/docs/reference/nextjs/clerk-middleware#dynamic-keys',
206-
);
207-
208-
return;
203+
throw new Error(encryptionKeyMissing);
209204
}
210205

211206
const maybeKeylessEncryptionKey = isProductionEnvironment()

0 commit comments

Comments
 (0)