-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Error: headers
was called outside a request scope, when using Authjs v5.0.0-beta.19 and next dev --turbo
#11076
Comments
I am getting this: "use client";
import { SessionProvider } from "next-auth/react";
import { getServerSession } from "next-auth";
import React, { ReactNode } from "react";
import { Toaster } from "react-hot-toast";
export default function Providers({ children }: { children: ReactNode }) {
const session = getServerSession();
console.log('straight from providers,,', session)
return (
<SessionProvider session={session}>
<Toaster position="top-center" reverseOrder={false} />
{children}
</SessionProvider>
);
} What am I doing wrong? I need this to access useSession in client components but it does not work. EDIT: I dont know how to do this in Next14 layouts: import { SessionProvider } from "next-auth/react"
export default function App({
Component,
pageProps: { session, ...pageProps },
}) {
return (
<SessionProvider session={session}>
<Component {...pageProps} />
</SessionProvider>
)
} |
@Qodestackr I would like to point out that wrapping your app directly with sessionprovider doesnot work instead import it in a client component and then wrap that component around your app LIKE THIS:
And for the component
|
First thing first why did you write "use server" on the server component By default it was server component by marking you have made it a server action that works like a post request
|
|
import xior from "xior"
Same error here, in any beta version of next-auth |
Thanks, I think I just overlooked that when I was trying different things in hope, I've removed it now and still get the issue. |
I just have the same issue "use client";
const Parent = ({component}: {component: ReactNode}) => {
// ---- other work
return (
<div>
{component}
</div>
)
} const ServerComponent= ({id}: {id: string})=> {
const session = await auth();
return (
// ----
)
}
const X = () => {
const id = "xxxx";
return (
<Parent
component={<ServerComponent id={id}/>}
/>
)
} this cause the issue:
|
I create a file get-session.tsx
and it finally works. |
I tried cloning and running the repository but it does not seen to work even after installing all the modules.
|
I have myself implemented basic authentication using authjs and mongo db along with credentials and oauth providers and also implemented basic stripe payment . Take a look at the repository Here Next-auth-toolkit |
Also the official documentation suggests to create the auth.js file in the root of the directory. Docs |
Hey @Ali-Raza764 thanks, odd it doesn't work for you, works for me doing the below
My app/auth works when running 'npm run dev' (next dev) |
Environment
Reproduction URL
https://github.com/cogb-jclaney/authjs-issue
Describe the issue
When running a Next JS site using Authjs v5.0.0-beta.19 and next dev --turbo, I get the following error - "Error:
headers
was called outside a request scope", running next dev without the --turbo flag works as previous.Authjs v5.0.0-beta.18
next dev (works)
next dev --turbo (works)
Authjs v5.0.0-beta.19
next dev (works)
next dev --turbo (causes the error)
How to reproduce
Running the command "npm run dev" when "--turbo" is enabled cause the application to error.
Running the command without "--turbo" works normally and both with and without work on the previous version (v5.0.0-beta.18).
Credential provider has been configured for the example, no inputs actually needed, user has been hardcoded.
Expected behavior
The session from "await auth()" should be returned.
The text was updated successfully, but these errors were encountered: