Skip to content

Commit 7ad055a

Browse files
panteliselefwobsoriano
authored andcommitted
chore(nextjs): Remove unused code (#4980)
1 parent 2a03cf1 commit 7ad055a

File tree

7 files changed

+4
-65
lines changed

7 files changed

+4
-65
lines changed

.changeset/cold-radios-invent.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/nextjs/src/server/createGetAuth.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import type { AuthObject } from '@clerk/backend';
22
import { constants } from '@clerk/backend/internal';
3-
import { decodeJwt } from '@clerk/backend/jwt';
43
import { isTruthy } from '@clerk/shared/underscore';
54

65
import { withLogger } from '../utils/debugLogger';
76
import { getAuthDataFromRequest } from './data/getAuthDataFromRequest';
87
import { getAuthAuthHeaderMissing } from './errors';
98
import { getHeader } from './headers-utils';
109
import type { RequestLike } from './types';
11-
import { assertAuthStatus, getCookie } from './utils';
10+
import { assertAuthStatus } from './utils';
1211

1312
export const createGetAuth = ({
1413
noAuthStatusMessage,
@@ -33,9 +32,3 @@ export const getAuth = createGetAuth({
3332
debugLoggerName: 'getAuth()',
3433
noAuthStatusMessage: getAuthAuthHeaderMissing(),
3534
});
36-
37-
export const parseJwt = (req: RequestLike) => {
38-
const cookieToken = getCookie(req, constants.Cookies.Session);
39-
const headerToken = getHeader(req, 'authorization')?.replace('Bearer ', '');
40-
return decodeJwt(cookieToken || headerToken || '');
41-
};

packages/nextjs/src/server/errors.ts

-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ export const authAuthHeaderMissing = (helperName = 'auth') =>
2929
For more details, see https://clerk.com/docs/quickstarts/nextjs
3030
`;
3131

32-
export const clockSkewDetected = (verifyMessage: string) =>
33-
`Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as "expired" due to clock skew.
34-
35-
To resolve this issue, make sure your system's clock is set to the correct time (e.g. turn off and on automatic time synchronization).
36-
37-
---
38-
39-
${verifyMessage}`;
40-
4132
export const authSignatureInvalid = `Clerk: Unable to verify request, this usually means the Clerk middleware did not run. Ensure Clerk's middleware is properly integrated and matches the current route. For more information, see: https://clerk.com/docs/references/nextjs/clerk-middleware. (code=auth_signature_invalid)`;
4233

4334
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/references/nextjs/clerk-middleware#dynamic-keys. (code=encryption_key_invalid)`;

packages/nextjs/src/server/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export type { ClerkMiddlewareAuth, ClerkMiddlewareAuthObject, ClerkMiddlewareOpt
4444
*/
4545
export type {
4646
OrganizationMembershipRole,
47-
// Webhook event types
4847
// Resources
4948
AllowlistIdentifier,
5049
Client,

packages/nextjs/src/server/url.ts

-18
This file was deleted.

packages/nextjs/src/server/utils.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { handleValueOrFn, isProductionEnvironment } from '@clerk/shared/utils';
77
import AES from 'crypto-js/aes';
88
import encUtf8 from 'crypto-js/enc-utf8';
99
import hmacSHA1 from 'crypto-js/hmac-sha1';
10-
import type { NextRequest } from 'next/server';
1110
import { NextResponse } from 'next/server';
1211

1312
import { constants as nextConstants } from '../constants';
@@ -21,24 +20,9 @@ import {
2120
missingSignInUrlInDev,
2221
} from './errors';
2322
import { errorThrower } from './errorThrower';
24-
import { detectClerkMiddleware, isNextRequest } from './headers-utils';
23+
import { detectClerkMiddleware } from './headers-utils';
2524
import type { RequestLike } from './types';
2625

27-
export function getCookie(req: RequestLike, name: string): string | undefined {
28-
if (isNextRequest(req)) {
29-
// Nextjs broke semver in the 13.0.0 -> 13.0.1 release, so even though
30-
// this should be RequestCookie in all updated apps. In order to support apps
31-
// using v13.0.0 still, we explicitly add the string type
32-
// https://github.com/vercel/next.js/pull/41526
33-
const reqCookieOrString = req.cookies.get(name) as ReturnType<NextRequest['cookies']['get']> | string | undefined;
34-
if (!reqCookieOrString) {
35-
return undefined;
36-
}
37-
return typeof reqCookieOrString === 'string' ? reqCookieOrString : reqCookieOrString.value;
38-
}
39-
return req.cookies[name];
40-
}
41-
4226
const OVERRIDE_HEADERS = 'x-middleware-override-headers';
4327
const MIDDLEWARE_HEADER_PREFIX = 'x-middleware-request' as string;
4428

packages/nextjs/src/utils/response.ts

-12
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,3 @@ export const setHeader = <T extends Response>(res: T, name: string, val: string)
88
res.headers.set(name, val);
99
return res;
1010
};
11-
12-
export const stringifyHeaders = (headers: { forEach: Headers['forEach'] }) => {
13-
if (!headers) {
14-
return JSON.stringify({});
15-
}
16-
17-
const obj: Record<string, string> = {};
18-
headers.forEach((value, name) => {
19-
obj[name] = value;
20-
});
21-
return JSON.stringify(obj);
22-
};

0 commit comments

Comments
 (0)