Skip to content

Commit

Permalink
fix(nextjs): ESLint corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilewski committed Oct 31, 2023
1 parent c5acf18 commit 12581f2
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ exports[`/api public exports should not include a breaking change 1`] = `
"Session",
"SignInToken",
"Token",
"TokenVerificationError",
"TokenVerificationErrorAction",
"TokenVerificationErrorCode",
"TokenVerificationErrorReason",
"User",
"Verification",
"allowlistIdentifiers",
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/app-beta/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ deprecated(
'@clerk/nextjs/app-beta',
'Use imports from `@clerk/nextjs` instead.\nFor more details, consult the middleware documentation: https://clerk.com/docs/nextjs/middleware',
);
/* eslint-disable turbo/no-undeclared-env-vars */

import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type { InitialState, PublishableKeyOrFrontendApi } from '@clerk/types';
import React from 'react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const useAwaitableNavigate = () => {
const { push } = useRouter();
const pathname = usePathname();
const params = useSearchParams();
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands

const urlKey = pathname + params.toString();

useEffect(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/src/app-router/server/currentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { User } from '@clerk/backend';
import { clerkClient } from '../../server/clerkClient';
import { auth } from './auth';

// eslint-disable-next-line @typescript-eslint/require-await
export async function currentUser(): Promise<User | null> {
const { userId } = auth();
return userId ? clerkClient.users.getUser(userId) : null;
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/client-boundary/NextOptionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const ClerkNextOptionsCtx = React.createContext<{ value: ClerkNextContextValue }
ClerkNextOptionsCtx.displayName = 'ClerkNextOptionsCtx';

const useClerkNextOptions = () => {
const ctx = React.useContext(ClerkNextOptionsCtx)!;
return ctx.value as ClerkNextContextValue;
const ctx = React.useContext(ClerkNextOptionsCtx) as { value: ClerkNextContextValue };
return ctx.value;
};

const ClerkNextOptionsProvider = (props: React.PropsWithChildren<{ options: ClerkNextContextValue }>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ exports[`/edge-middleware public exports should not include a breaking change 1`
"Session",
"SignInToken",
"Token",
"TokenVerificationError",
"TokenVerificationErrorAction",
"TokenVerificationErrorCode",
"TokenVerificationErrorReason",
"User",
"Verification",
"allowlistIdentifiers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ exports[`/server public exports should not include a breaking change 1`] = `
"Session",
"SignInToken",
"Token",
"TokenVerificationError",
"TokenVerificationErrorAction",
"TokenVerificationErrorCode",
"TokenVerificationErrorReason",
"User",
"Verification",
"auth",
Expand Down
7 changes: 3 additions & 4 deletions packages/nextjs/src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import type { AuthObject, RequestState } from '@clerk/backend';
import { buildRequestUrl, constants } from '@clerk/backend';
import { buildRequestUrl, constants, TokenVerificationErrorReason } from '@clerk/backend';
import type Link from 'next/link';
import type { NextFetchEvent, NextMiddleware, NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
Expand Down Expand Up @@ -355,7 +354,7 @@ const assertClockSkew = (requestState: RequestState, opts: AuthMiddlewareParams)
return;
}

if (requestState.reason === 'token-not-active-yet') {
if (requestState.reason === TokenVerificationErrorReason.TokenNotActiveYet) {
throw new Error(clockSkewDetected(requestState.message));
}
};
Expand All @@ -377,7 +376,7 @@ const assertInfiniteRedirectionLoop = (
if (infiniteRedirectsCounter === 6) {
// Infinite redirect detected, is it clock skew?
// We check for token-expired here because it can be a valid, recoverable scenario, but in a redirect loop a token-expired error likely indicates clock skew.
if (requestState.reason === 'token-expired') {
if (requestState.reason === TokenVerificationErrorReason.TokenExpired) {
throw new Error(clockSkewDetected(requestState.message));
}

Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/src/server/clerkClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { Clerk } from '@clerk/backend';

import { API_KEY, API_URL, API_VERSION, DOMAIN, IS_SATELLITE, PROXY_URL, SECRET_KEY } from './constants';
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { NextResponse } from 'next/server';
import { constants as nextConstants } from '../constants';
import { API_KEY, DOMAIN, IS_SATELLITE, PROXY_URL, SECRET_KEY, SIGN_IN_URL } from './clerkClient';
import { missingDomainAndProxy, missingSignInUrlInDev } from './errors';
import type { NextMiddlewareResult, RequestLike } from './types';
import type { WithAuthOptions } from './types';
import type { NextMiddlewareResult, RequestLike, WithAuthOptions } from './types';

type AuthKey = 'AuthStatus' | 'AuthMessage' | 'AuthReason';

Expand All @@ -18,7 +17,7 @@ export function setCustomAttributeOnRequest(req: RequestLike, key: string, value
}

export function getCustomAttributeFromRequest(req: RequestLike, key: string): string | null | undefined {
// @ts-expect-error
// @ts-expect-error - TS doesn't like indexing into RequestLike
return key in req ? req[key] : undefined;
}

Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/src/utils/mergeNextClerkPropsWithEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import type { NextClerkProviderProps } from '../types';

export const mergeNextClerkPropsWithEnv = (props: Omit<NextClerkProviderProps, 'children'>) => {
Expand Down

0 comments on commit 12581f2

Please sign in to comment.