Skip to content
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

chore(nextjs): Apply deprecation warnings #1760

Merged
merged 6 commits into from
Sep 28, 2023
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
5 changes: 5 additions & 0 deletions .changeset/spicy-toys-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': patch
---

Warn about deprecations that will be dropped in next major version
23 changes: 6 additions & 17 deletions packages/nextjs/src/server/clerkClient.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { Clerk } from '@clerk/backend';

/**
* @deprecated
*/
export const JS_VERSION = process.env.CLERK_JS_VERSION || '';
export const CLERK_JS_VERSION = process.env.NEXT_PUBLIC_CLERK_JS_VERSION || '';
export const CLERK_JS_URL = process.env.NEXT_PUBLIC_CLERK_JS || '';
export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.dev';
export const API_VERSION = process.env.CLERK_API_VERSION || 'v1';
export const API_KEY = process.env.CLERK_API_KEY || '';
export const SECRET_KEY = process.env.CLERK_SECRET_KEY || '';
export const FRONTEND_API = process.env.NEXT_PUBLIC_CLERK_FRONTEND_API || '';
export const PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY || '';
export const DOMAIN = process.env.NEXT_PUBLIC_CLERK_DOMAIN || '';
export const PROXY_URL = process.env.NEXT_PUBLIC_CLERK_PROXY_URL || '';
export const IS_SATELLITE = process.env.NEXT_PUBLIC_CLERK_IS_SATELLITE === 'true' || false;
export const SIGN_IN_URL = process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL || '';
export const SIGN_UP_URL = process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL || '';
import { API_KEY, API_URL, API_VERSION, DOMAIN, IS_SATELLITE, PROXY_URL, SECRET_KEY } from './constants';

const clerkClient = Clerk({
apiKey: API_KEY,
Expand All @@ -36,3 +20,8 @@ const createClerkClient = Clerk;
export { clerkClient, createClerkClient, Clerk };

export * from '@clerk/backend';

/**
* @deprecated Don't export the constants. Should be marked as internal
*/
export * from './constants';
34 changes: 34 additions & 0 deletions packages/nextjs/src/server/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { deprecated } from '@clerk/shared';

/**
* @deprecated Use `CLERK_JS_VERSION` instead.
*/
export const JS_VERSION = process.env.CLERK_JS_VERSION || '';
if (JS_VERSION) {
deprecated('CLERK_JS_VERSION', 'Use `NEXT_PUBLIC_CLERK_JS_VERSION` environment variable instead.');
}
export const CLERK_JS_VERSION = process.env.NEXT_PUBLIC_CLERK_JS_VERSION || '';
export const CLERK_JS_URL = process.env.NEXT_PUBLIC_CLERK_JS || '';
export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.dev';
export const API_VERSION = process.env.CLERK_API_VERSION || 'v1';
/**
* @deprecated Use `CLERK_SECRET_KEY` instead.
*/
export const API_KEY = process.env.CLERK_API_KEY || '';
if (API_KEY) {
deprecated('CLERK_API_KEY', 'Use `CLERK_SECRET_KEY` environment variable instead.');
}
export const SECRET_KEY = process.env.CLERK_SECRET_KEY || '';
/**
* @deprecated Use `PUBLISHABLE_KEY` instead.
*/
export const FRONTEND_API = process.env.NEXT_PUBLIC_CLERK_FRONTEND_API || '';
if (FRONTEND_API) {
deprecated('NEXT_PUBLIC_CLERK_FRONTEND_API', 'Use `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` environment variable instead.');
}
export const PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY || '';
export const DOMAIN = process.env.NEXT_PUBLIC_CLERK_DOMAIN || '';
export const PROXY_URL = process.env.NEXT_PUBLIC_CLERK_PROXY_URL || '';
export const IS_SATELLITE = process.env.NEXT_PUBLIC_CLERK_IS_SATELLITE === 'true' || false;
export const SIGN_IN_URL = process.env.NEXT_PUBLIC_CLERK_SIGN_IN_URL || '';
export const SIGN_UP_URL = process.env.NEXT_PUBLIC_CLERK_SIGN_UP_URL || '';
6 changes: 6 additions & 0 deletions packages/nextjs/src/server/withClerkMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RequestState } from '@clerk/backend';
import { constants, debugRequestState } from '@clerk/backend';
import { deprecated } from '@clerk/shared';
import type { NextFetchEvent, NextMiddleware, NextRequest } from 'next/server';
import { NextResponse } from 'next/server';

Expand Down Expand Up @@ -36,6 +37,11 @@ export const withClerkMiddleware: WithClerkMiddleware = (...args: unknown[]) =>
const noop = () => undefined;
const [handler = noop, opts = {}] = args as [NextMiddleware, WithAuthOptions] | [];

deprecated(
'withClerkMiddleware',
'Use `authMiddleware` instead.\nFor more details, consult the middleware documentation: https://clerk.com/docs/nextjs/middleware',
);

return async (req: NextRequest, event: NextFetchEvent) => {
const { isSatellite, domain, signInUrl, proxyUrl } = handleMultiDomainAndProxy(req, opts);

Expand Down
5 changes: 5 additions & 0 deletions packages/nextjs/src/ssr/withServerSideAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RequestState } from '@clerk/backend';
import { constants, debugRequestState } from '@clerk/backend';
import { deprecated } from '@clerk/shared';
import type { ServerResponse } from 'http';
import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';

Expand Down Expand Up @@ -43,6 +44,10 @@ const decorateResponseWithObservabilityHeaders = (res: ServerResponse, requestSt
export const withServerSideAuth: WithServerSideAuth = (cbOrOptions: any, options?: any): any => {
const cb = typeof cbOrOptions === 'function' ? cbOrOptions : undefined;
const opts = (options ? options : typeof cbOrOptions !== 'function' ? cbOrOptions : {}) || {};
deprecated(
'withServerSideAuth',
'Use `authMiddleware` instead.\nFor more details, consult the middleware documentation: https://clerk.com/docs/nextjs/middleware',
);

// Support both loadOrganization and the older loadOrg option without breaking changes
// TODO: Remove pre v5
Expand Down
21 changes: 20 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@
"tsconfig.json",
"tsconfig.*.json"
],
"globalEnv": ["NODE_VERSION", "NPM_VERSION", "NODE_ENV", "VERCEL"],
"globalEnv": [
"NODE_VERSION",
"NPM_VERSION",
"NODE_ENV",
"VERCEL",
"CLERK_JS_VERSION",
"CLERK_API_URL",
"CLERK_API_VERSION",
"CLERK_API_KEY",
"CLERK_SECRET_KEY",
"NEXT_PUBLIC_CLERK_JS_VERSION",
"NEXT_PUBLIC_CLERK_JS",
"NEXT_PUBLIC_CLERK_FRONTEND_API",
"NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY",
"NEXT_PUBLIC_CLERK_DOMAIN",
"NEXT_PUBLIC_CLERK_PROXY_URL",
"NEXT_PUBLIC_CLERK_IS_SATELLITE",
"NEXT_PUBLIC_CLERK_SIGN_IN_URL",
"NEXT_PUBLIC_CLERK_SIGN_UP_URL"
],
"pipeline": {
"build": {
"dependsOn": ["^build"],
Expand Down