Closed
Description
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
Related to some of the other App Router bugs open.
Instead of doing the withPageAuthRequired
on each Page, I'd like to just put it on the layout.
e.g.:
export default withPageAuthRequired(async function BaseLayout({
children,
}: {
children: React.ReactNode;
}) {
const session = await getSession();
return (
<div>
Hello {session?.user.name},
<br />
<a href="/api/auth/logout">Logout</a>
<br />
<a href="/api/auth/login">Login</a>
<div>{children}</div>
</div>
);
});
This code seems to work as expected but will throw a typescript error:
Seems like only the typing would need to be enhanced.
It also be nice to be able to access the current route in the returnTo
func which makes this use case even better:
export default withPageAuthRequired(async function BaseLayout({
children,
}: {
children: React.ReactNode;
}) {
...
return (
<div>
...
</div>
);
}, {
// Pass in pathname on top of dynamic pieces
returnTo: ({ pathname } => pathname);
});
Reproduction
Use above code example.
Additional context
No response
nextjs-auth0 version
3.5.0
Next.js version
14.1
Node.js version
18.17.1
Metadata
Metadata
Assignees
Labels
No labels