Next.js Discord

Discord Forum

Accessing NextRequest in a Server Action

Answered
Schweizerischer Niederlaufhund posted this in #help-forum
Open in Discord
Schweizerischer NiederlaufhundOP
I'd like to check if the currentUser is authenticated when a server action is triggered. The docs suggest this design pattern (https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#authentication-and-authorization) but most auth libraries (like next-auth) require you to pass in a the request object to parse out the session/jwt information. How can I access the request object in a Server Action? Or is this not supported and my only option is to create an API endpoint for this work?

Thanks!
Answered by Ray
anyway, you can always access the header and cookies with header() or cookie() function
View full answer

4 Replies