Skip to content

Commit

Permalink
feat(nextjs): Move server-related APIs to /server
Browse files Browse the repository at this point in the history
chore(repo): Add changesets

chore(repo): Update changesets
  • Loading branch information
nikosdouvlis committed Dec 14, 2023
1 parent f885d52 commit d04efe7
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 120 deletions.
13 changes: 13 additions & 0 deletions .changeset/grumpy-drinks-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@clerk/nextjs': major
---

Drop support for NextJS v12: v12 was released on 26 Oct 2021. Support for security updates stopped on 21 Nov 2022.

Drop support for NextJS <13.0.4: Various header-related bugs were introduced with the 12.1.0, 12.2.0, 13.0.1, 13.0.2, 13.0.3 NextJS releases which are now fixed since next@^13.0.4. We will be dropping support for these problematic versions in order to greatly reduce complexity in our codebase.

Drop support for NextJS < 14.0.3 because of the issues described here: https://github.com/clerk/javascript/issues/1436.

Deprecate `authMiddleware` in favor of `clerkMiddleware`. For more information, see https://clerk.com/docs/upgrade-guides/v5-introduction

Move the server-side APIs from `@clerk/nextjs` to the `@clerk/nextjs/server` module: `WebhookEventType`, `WebhookEvent`, `verifyToken`, `redirectToSignIn`, `auth`, `buildClerkProps`, `clerkClient`, `currentUser`, `getAuth`, `redirectToSignUp` and `authMiddleware`. For more information, see https://clerk.com/docs/upgrade-guides/v5-introduction
5 changes: 5 additions & 0 deletions .changeset/tricky-bikes-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': major
---

Drop unused SearchParams.AuthStatus constant
6 changes: 3 additions & 3 deletions packages/nextjs/errors/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"main": "../dist/errors/index.js",
"module": "../dist/errors/index.mjs",
"types": "../dist/types/errors/index.d.ts"
"main": "../dist/cjs/errors.js",
"module": "../dist/esm/errors.js",
"types": "../dist/types/errors.d.ts"
}
8 changes: 0 additions & 8 deletions packages/nextjs/package.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
"#components": {
"react-server": "./components.server.js",
"default": "./components.client.js"
},
"#server": {
"react-server": "./server-helpers.server.js",
"edge-light": "./server-helpers.server.js",
"worker": "./server-helpers.server.js",
"node": "./server-helpers.server.js",
"browser": "./server-helpers.client.js",
"default": "./server-helpers.client.js"
}
}
}
8 changes: 0 additions & 8 deletions packages/nextjs/package.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
"#components": {
"react-server": "./components.server.js",
"default": "./components.client.js"
},
"#server": {
"react-server": "./server-helpers.server.js",
"edge-light": "./server-helpers.server.js",
"worker": "./server-helpers.server.js",
"node": "./server-helpers.server.js",
"browser": "./server-helpers.client.js",
"default": "./server-helpers.client.js"
}
}
}
1 change: 1 addition & 0 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"require": "./dist/cjs/errors.js"
}
},
"types": "./dist/types/index.d.ts",
"files": [
"dist",
"server",
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/src/app-router/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { NextRequest } from 'next/server';

export const buildRequestLike = () => {
try {
console.log(NextRequest);
return new NextRequest('https://placeholder.com', { headers: headers() });
} catch (e: any) {
if (
Expand Down
30 changes: 5 additions & 25 deletions packages/nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,11 @@ export {
*/
// @ts-ignore
import * as ComponentsModule from '#components';
/**
* Conditionally export server-side helpers.
* This allows to import server-side helpers from the top-level path.
* We defined the runtime and the type values explicitly,
* because TS will not recognize the subpath import unless the HOST
* application sets moduleResolution to 'NodeNext'.
*/
// @ts-ignore
import * as ServerHelperModule from '#server';

import type { ServerComponentsServerModuleTypes } from './components.server';
import type { ServerHelpersServerModuleTypes } from './server-helpers.server';

export const ClerkProvider = ComponentsModule.ClerkProvider as ServerComponentsServerModuleTypes['ClerkProvider'];
export const SignedIn = ComponentsModule.SignedIn as ServerComponentsServerModuleTypes['SignedIn'];
export const SignedOut = ComponentsModule.SignedOut as ServerComponentsServerModuleTypes['SignedOut'];

export const Protect = ComponentsModule.Protect;

export const auth = ServerHelperModule.auth as ServerHelpersServerModuleTypes['auth'];
export const currentUser = ServerHelperModule.currentUser as ServerHelpersServerModuleTypes['currentUser'];
// export const getAuth = ServerHelperModule.getAuth as ServerHelpersServerModuleTypes['getAuth'];
export const clerkClient = ServerHelperModule.clerkClient as ServerHelpersServerModuleTypes['clerkClient'];
export const authMiddleware = ServerHelperModule.authMiddleware as ServerHelpersServerModuleTypes['authMiddleware'];
export const redirectToSignIn =
ServerHelperModule.redirectToSignIn as ServerHelpersServerModuleTypes['redirectToSignIn'];
export const redirectToSignUp =
ServerHelperModule.redirectToSignUp as ServerHelpersServerModuleTypes['redirectToSignUp'];
export const ClerkProvider =
ComponentsModule.ClerkProvider as unknown as ServerComponentsServerModuleTypes['ClerkProvider'];
export const SignedIn = ComponentsModule.SignedIn as unknown as ServerComponentsServerModuleTypes['SignedIn'];
export const SignedOut = ComponentsModule.SignedOut as unknown as ServerComponentsServerModuleTypes['SignedOut'];
export const Protect = ComponentsModule.Protect as unknown as ServerComponentsServerModuleTypes['Protect'];
11 changes: 0 additions & 11 deletions packages/nextjs/src/server-helpers.client.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/nextjs/src/server-helpers.server.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,14 @@

exports[`/server public exports should not include a breaking change 1`] = `
[
"AllowlistIdentifier",
"AuthStatus",
"Client",
"DeletedObject",
"Email",
"EmailAddress",
"ExternalAccount",
"IdentificationLink",
"Invitation",
"OauthAccessToken",
"ObjectType",
"Organization",
"OrganizationInvitation",
"OrganizationMembership",
"OrganizationMembershipPublicUserData",
"PhoneNumber",
"RedirectUrl",
"SMSMessage",
"Session",
"SignInToken",
"Token",
"TokenVerificationError",
"TokenVerificationErrorReason",
"User",
"Verification",
"auth",
"authMiddleware",
"buildClerkProps",
"buildRequestUrl",
"clerkClient",
"constants",
"createAuthenticateRequest",
"createClerkClient",
"createIsomorphicRequest",
"currentUser",
"debugRequestState",
"decodeJwt",
"deserialize",
"getAuth",
"hasValidSignature",
"makeAuthObjectSerializable",
"prunePrivateMetadata",
"redirect",
"redirectToSignIn",
"redirectToSignUp",
"sanitizeAuthObject",
"signJwt",
"signedInAuthObject",
"signedOutAuthObject",
"verifyJwt",
"verifyToken",
]
`;
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export interface AuthMiddleware {

/**
* @deprecated Use `clerkMiddleware` instead.
* Migration guide: https://clerk.com/docs/migration-guides/v5
* Migration guide: https://clerk.com/docs/upgrade-guides/v5-introduction
*/
const authMiddleware: AuthMiddleware = (...args: unknown[]) => {
const [params = {}] = args as [AuthMiddlewareParams?];
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/src/server/clerkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ const clerkClient = createClerkClient({
});

export { clerkClient };
export * from '@clerk/backend';
12 changes: 10 additions & 2 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
export * from './clerkClient';
/**
* Generic exports
*/
export { verifyToken, createClerkClient } from '@clerk/backend';
export type { WebhookEvent, WebhookEventType } from '@clerk/backend';
export { clerkClient } from './clerkClient';

/**
* NextJS-specific exports
*/
export { buildClerkProps, getAuth } from './getAuth';
export { redirectToSignIn, redirectToSignUp } from './redirect';

export { auth } from '../app-router/server/auth';
export { currentUser } from '../app-router/server/currentUser';
export { authMiddleware } from './authMiddleware';

0 comments on commit d04efe7

Please sign in to comment.