fix: make withPageAuthRequired generic to support PageProps/LayoutProps types#2529
Conversation
…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:
|
|
Hi @sleitor, observed this pr a few failing checks. Could you please have a look into those !! |
|
@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 ( |
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