From e35151da230173d68243fd62b3a6b44da02212fe Mon Sep 17 00:00:00 2001 From: Alexander Hoekje List Date: Mon, 20 May 2024 13:09:06 -0700 Subject: [PATCH 1/2] with-page-auth-required.ts is incompatible with next14 app router --- src/helpers/with-page-auth-required.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/helpers/with-page-auth-required.ts b/src/helpers/with-page-auth-required.ts index e356bacf3..a9367e117 100644 --- a/src/helpers/with-page-auth-required.ts +++ b/src/helpers/with-page-auth-required.ts @@ -136,7 +136,7 @@ export type WithPageAuthRequiredAppRouterOptions = { * // app/protected-page/page.js * import { withPageAuthRequired } from '@auth0/nextjs-auth0'; * - * export default function withPageAuthRequired(ProtectedPage() { + * export default withPageAuthRequired(async function ProtectedPage() { * return
Protected content
; * }, { returnTo: '/protected-page' }); * ``` @@ -153,13 +153,15 @@ export type WithPageAuthRequiredAppRouterOptions = { * * ```js * // app/protected-page/[slug]/page.js - * import { withPageAuthRequired } from '@auth0/nextjs-auth0'; + * import { AppRouterPageRouteOpts, withPageAuthRequired } from '@auth0/nextjs-auth0'; * - * export default function withPageAuthRequired(ProtectedPage() { + * export default withPageAuthRequired(async function ProtectedPage({ + * params, searchParams + * }: AppRouterPageRouteOpts) { * return
Protected content
; * }, { * returnTo({ params }) { - * return `/protected-page/${params.slug}` + * return `/protected-page/${params?.slug}`; * } * }); * ``` From 5ed8ee328f6f7208806523e5a3e65f458eab1a28 Mon Sep 17 00:00:00 2001 From: Alexander Hoekje List Date: Mon, 20 May 2024 13:27:04 -0700 Subject: [PATCH 2/2] adds correct export --- src/helpers/with-page-auth-required.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/helpers/with-page-auth-required.ts b/src/helpers/with-page-auth-required.ts index a9367e117..7ef588548 100644 --- a/src/helpers/with-page-auth-required.ts +++ b/src/helpers/with-page-auth-required.ts @@ -136,9 +136,11 @@ export type WithPageAuthRequiredAppRouterOptions = { * // app/protected-page/page.js * import { withPageAuthRequired } from '@auth0/nextjs-auth0'; * - * export default withPageAuthRequired(async function ProtectedPage() { + * const ProtectedPage = withPageAuthRequired(async function ProtectedPage() { * return
Protected content
; * }, { returnTo: '/protected-page' }); + * + * export default ProtectedPage; * ``` * * If the user visits `/protected-page` without a valid session, it will redirect the user to the @@ -154,16 +156,19 @@ export type WithPageAuthRequiredAppRouterOptions = { * ```js * // app/protected-page/[slug]/page.js * import { AppRouterPageRouteOpts, withPageAuthRequired } from '@auth0/nextjs-auth0'; - * - * export default withPageAuthRequired(async function ProtectedPage({ + * + * const ProtectedPage = withPageAuthRequired(async function ProtectedPage({ * params, searchParams * }: AppRouterPageRouteOpts) { - * return
Protected content
; + * const slug = params?.slug as string; + * return
Protected content for {slug}
; * }, { * returnTo({ params }) { * return `/protected-page/${params?.slug}`; * } * }); + * + * export default ProtectedPage; * ``` * * @category Server