Skip to content
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/fluffy-eyes-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/nextjs": minor
---

Bug fix: Correctly redirect to sign in page in Next 15.
7 changes: 7 additions & 0 deletions packages/nextjs/src/server/nextFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ type NextFetcher = Fetcher & {
* Full type can be found https://github.com/vercel/next.js/blob/6185444e0a944a82e7719ac37dad8becfed86acd/packages/next/src/client/components/static-generation-async-storage.external.ts#L4
*/
interface StaticGenerationAsyncStorage {
/**
* Available for Next 14
*/
readonly pagePath?: string;
/**
* Available for Next 15
*/
readonly page?: string;
}

function isNextFetcher(fetch: Fetcher | NextFetcher): fetch is NextFetcher {
Expand Down
14 changes: 13 additions & 1 deletion packages/nextjs/src/server/protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,19 @@ const isAppRouterInternalNavigation = (req: Request) =>

const isPagePathAvailable = () => {
const __fetch = globalThis.fetch;
return Boolean(isNextFetcher(__fetch) ? __fetch.__nextGetStaticStore().getStore()?.pagePath : false);

if (!isNextFetcher(__fetch)) {
return false;
}

const { page, pagePath } = __fetch.__nextGetStaticStore().getStore() || {};

return Boolean(
// available on next@14
pagePath ||
// available on next@15
page,
);
};

const isPagesRouterInternalNavigation = (req: Request) => !!req.headers.get(nextConstants.Headers.NextjsData);
Expand Down
Loading