fix: make withPageAuthRequired generic to support PageProps/LayoutProps types#2529
Merged
Piyush-85 merged 3 commits intoauth0:mainfrom Mar 19, 2026
Merged
Conversation
Merged
Piyush-85
previously approved these changes
Mar 11, 2026
Contributor
…ps types
The AppRouterPageRoute type now accepts a generic parameter P that
extends AppRouterPageRouteOpts, allowing Next.js PageProps and
LayoutProps types to be used with withPageAuthRequired.
Before:
// TS error: Types of parameters 'props' and 'obj' are incompatible
export default auth0.withPageAuthRequired(
async function Page(props: PageProps<'/customers/[id]'>) { ... }
);
After:
// Works correctly, props.params is typed as Promise<{ id: string }>
export default auth0.withPageAuthRequired(
async function Page(props: PageProps<'/customers/[id]'>) { ... }
);
Closes auth0#2440
a6d4a7c to
7b64c2e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2529 +/- ##
=======================================
Coverage 90.50% 90.50%
=======================================
Files 52 52
Lines 6632 6634 +2
Branches 1380 1380
=======================================
+ Hits 6002 6004 +2
Misses 619 619
Partials 11 11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
Hi @sleitor, observed this pr a few failing checks. Could you please have a look into those !! |
Contributor
Author
|
@Piyush-85 Hi! I checked the CI status — the checks show as "action_required" which is standard for external PRs requiring maintainer CI approval to run workflows, not actual test failures. The local lint check passes ( |
Piyush-85
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2440
Problem
withPageAuthRequireddoes not accept Next.jsPagePropsorLayoutPropstypes becauseAppRouterPageRouteexpectsAppRouterPageRouteOptswith loosely-typedparams?: Promise<Record<string, string | string[]>>. Next.js typed routes produce narrower types (e.g.Promise<{ id: string }>) that are incompatible.Fix
Make
AppRouterPageRoute,WithPageAuthRequiredAppRouter, andappRouteHandlerFactorygeneric over the props typeP extends AppRouterPageRouteOpts. TypeScript infersPfrom the handler function, so the return type preserves the exact props type.Also works with
LayoutProps:Changes
src/server/helpers/with-page-auth-required.ts:AppRouterPageRoute<P>— generic with defaultAppRouterPageRouteOptsWithPageAuthRequiredAppRouter— generic, infersPfrom handlerappRouteHandlerFactory— propagates generic through implementationTesting