Skip to content

Commit

Permalink
fix(nextjs): Move server-only resolution to runtime (#3761)
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraBeatris authored Jul 18, 2024
1 parent c21ba46 commit b8e3129
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-olives-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/nextjs": patch
---

Fixes regression on `@clerk/nextjs/server` (introduced on https://github.com/clerk/javascript/pull/3758) where `server-only` module was being resolved in runtimes without `react-server` available, such as `getAuth` on `getServerSideProps`.
4 changes: 2 additions & 2 deletions packages/nextjs/src/app-router/server/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'server-only';

import type { AuthObject, RedirectFun } from '@clerk/backend/internal';
import { constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { notFound, redirect } from 'next/navigation';
Expand All @@ -16,6 +14,8 @@ import { buildRequestLike } from './utils';
type Auth = AuthObject & { protect: AuthProtect; redirectToSignIn: RedirectFun<ReturnType<typeof redirect>> };

export const auth = (): Auth => {
require('server-only');

const request = buildRequestLike();
const authObject = createGetAuth({
debugLoggerName: 'auth()',
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/app-router/server/currentUser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'server-only';

import type { User } from '@clerk/backend';

import { clerkClient } from '../../server/clerkClient';
import { auth } from './auth';

export async function currentUser(): Promise<User | null> {
require('server-only');

const { userId } = auth();
if (!userId) {
return null;
Expand Down

0 comments on commit b8e3129

Please sign in to comment.