nextjs-auth0 icon indicating copy to clipboard operation
nextjs-auth0 copied to clipboard

Recommended way to use with React server actions

Open nimeshnayaju opened this issue 11 months ago • 0 comments

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):

  1. A "higher order" server action that accepts a server action and and returns a server action after performing authentication related logic.
  2. Expose necessary primitives with detailed code snippets on how to use them with server actions. Could be extended to API routes too.
  3. If no new feature needed, examples on how to deal with authentication inside server actions.

nimeshnayaju avatar Mar 21 '24 16:03 nimeshnayaju