-
Notifications
You must be signed in to change notification settings - Fork 26k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEXT-1290] getServerSession in ServerAction #50658
Comments
@bfourgeaud Have you tried passing the action as a prop to the client component? https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions#props |
Yes, this will fix the issue. I'm not sure if this is a bug or by design. |
✔️ Ok it works when passing down props instead of making the call inside the server action. But it would simplify props handling if it were possible. For now I have to pass down session 3 levels down ( Before closing, maybe wait if that is intended behaviour or bug ? |
Im having the same issue, but it seems to be from the next/headers cookies package, not next-auth, or in my case auth-helpers from Supabase |
For me, this problem only happens with a |
There're 3 layers in the RSC module graph: server → client → action. "Action" means that a Client Component re-enters the server layer by importing a file with `"use server"`, and it should behave the same as the server layer but you can't enter the client layer again (hence we have a 3rd layer name). Since the action layer has the same behavior and module resolution rules, it should be bundled just like the server layer. Closes #50658. Originally the issue was that `auth/next` isn't being bundled on the action layer, and it has the async local storage imported. Because of that, that storage comes from node_modules instead of the server bundle. fix NEXT-1290
Confirmed, 'use client';
import { logout } from './(auth)/logout/actions';
export function LogoutButton() {
return (
<form>
<button formAction={logout}>
logout
</button>
</form>
);
} Before
AfterNo error! 🎉 Thanks again @shuding 🙌 |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
https://github.com/bfourgeaud/server-actions-session-repro
To Reproduce
1 - Login (with any credentials)
2 - Click "Server Action" button
3 - See error on server side (terminal)
Describe the Bug
Whenever I try to use
getServerSession
fromnext-auth
in a server action, the server throws an error :Error: Invariant: Method expects to have requestAsyncStorage, none available
On the other hand, on any other server component (home page of reproduction for example), there is no problem retrieving the current session.
Expected Behavior
It should be possible to retrieve session information in server-actions the same way we retrieve them in any server-component.
Which browser are you using? (if relevant)
chrome
How are you deploying your application? (if relevant)
next dev
NEXT-1290
The text was updated successfully, but these errors were encountered: