Skip to content

chore(nextjs): Remove unused code #4980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/cold-radios-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
9 changes: 1 addition & 8 deletions packages/nextjs/src/server/createGetAuth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { AuthObject } from '@clerk/backend';
import { constants } from '@clerk/backend/internal';
import { decodeJwt } from '@clerk/backend/jwt';
import { isTruthy } from '@clerk/shared/underscore';

import { withLogger } from '../utils/debugLogger';
import { getAuthDataFromRequest } from './data/getAuthDataFromRequest';
import { getAuthAuthHeaderMissing } from './errors';
import { getHeader } from './headers-utils';
import type { RequestLike } from './types';
import { assertAuthStatus, getCookie } from './utils';
import { assertAuthStatus } from './utils';

export const createGetAuth = ({
noAuthStatusMessage,
Expand All @@ -33,9 +32,3 @@ export const getAuth = createGetAuth({
debugLoggerName: 'getAuth()',
noAuthStatusMessage: getAuthAuthHeaderMissing(),
});

export const parseJwt = (req: RequestLike) => {
const cookieToken = getCookie(req, constants.Cookies.Session);
const headerToken = getHeader(req, 'authorization')?.replace('Bearer ', '');
return decodeJwt(cookieToken || headerToken || '');
};
9 changes: 0 additions & 9 deletions packages/nextjs/src/server/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ export const authAuthHeaderMissing = (helperName = 'auth') =>
For more details, see https://clerk.com/docs/quickstarts/nextjs
`;

export const clockSkewDetected = (verifyMessage: string) =>
`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.

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).

---

${verifyMessage}`;

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)`;

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)`;
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export type { ClerkMiddlewareAuth, ClerkMiddlewareAuthObject, ClerkMiddlewareOpt
*/
export type {
OrganizationMembershipRole,
// Webhook event types
// Resources
AllowlistIdentifier,
Client,
Expand Down
18 changes: 0 additions & 18 deletions packages/nextjs/src/server/url.ts

This file was deleted.

18 changes: 1 addition & 17 deletions packages/nextjs/src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { handleValueOrFn, isProductionEnvironment } from '@clerk/shared/utils';
import AES from 'crypto-js/aes';
import encUtf8 from 'crypto-js/enc-utf8';
import hmacSHA1 from 'crypto-js/hmac-sha1';
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';

import { constants as nextConstants } from '../constants';
Expand All @@ -21,24 +20,9 @@ import {
missingSignInUrlInDev,
} from './errors';
import { errorThrower } from './errorThrower';
import { detectClerkMiddleware, isNextRequest } from './headers-utils';
import { detectClerkMiddleware } from './headers-utils';
import type { RequestLike } from './types';

export function getCookie(req: RequestLike, name: string): string | undefined {
if (isNextRequest(req)) {
// Nextjs broke semver in the 13.0.0 -> 13.0.1 release, so even though
// this should be RequestCookie in all updated apps. In order to support apps
// using v13.0.0 still, we explicitly add the string type
// https://github.com/vercel/next.js/pull/41526
const reqCookieOrString = req.cookies.get(name) as ReturnType<NextRequest['cookies']['get']> | string | undefined;
if (!reqCookieOrString) {
return undefined;
}
return typeof reqCookieOrString === 'string' ? reqCookieOrString : reqCookieOrString.value;
}
return req.cookies[name];
}

const OVERRIDE_HEADERS = 'x-middleware-override-headers';
const MIDDLEWARE_HEADER_PREFIX = 'x-middleware-request' as string;

Expand Down
12 changes: 0 additions & 12 deletions packages/nextjs/src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,3 @@ export const setHeader = <T extends Response>(res: T, name: string, val: string)
res.headers.set(name, val);
return res;
};

export const stringifyHeaders = (headers: { forEach: Headers['forEach'] }) => {
if (!headers) {
return JSON.stringify({});
}

const obj: Record<string, string> = {};
headers.forEach((value, name) => {
obj[name] = value;
});
return JSON.stringify(obj);
};
Loading