nextjs-auth0
nextjs-auth0 copied to clipboard
Recommended way to use with React server actions
Checklist
- [X] I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- [X] I have looked into the API documentation and have not found a suitable solution or answer.
- [X] I have searched the issues and have not found a suitable solution or answer.
- [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- [X] I agree to the terms within the Auth0 Code of Conduct.
Describe the problem you'd like to have solved
Hi, thanks for all the work on v3 and making the library compatible with the Next.js App Router. I am mostly curious about the recommended way to use the library with react server actions. I noticed in the withApiAuthRequired
method, there are some cookie related logic (setting cookies, etc) and was wondering about the best practice when using the library with server actions.
Describe the ideal solution
I do not have an ideal solution in mind, but here are some potential solutions (one I can think of):
- A "higher order" server action that accepts a server action and and returns a server action after performing authentication related logic.
- Expose necessary primitives with detailed code snippets on how to use them with server actions. Could be extended to API routes too.
- If no new feature needed, examples on how to deal with authentication inside server actions.