getServerAuthSession at any place crashes my app. 5000+ errors per second!

Below, I have my server component for rendering a hamburger menu based on whether the user is authenticated.
const SidebarMobile = async () => {
const session = await getServerAuthSession();

return session && session.user ? (
<Sheet>
...
</Sheet>
) : null;
};
const SidebarMobile = async () => {
const session = await getServerAuthSession();

return session && session.user ? (
<Sheet>
...
</Sheet>
) : null;
};
When I check the Network tab, main-app.js stays in an endless waterfall of downloading content. When I check the Console tab, this error is raised infinitely. It raises this error around 5.000 per second!
Uncaught (in promise) Error: Invariant: Method expects to have requestAsyncStorage, none available
at headers (webpack-internal:///(app-client)/./node_modules/.pnpm/next@13.4.3_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/client/components/headers.js:36:15)
at getServerSession (webpack-internal:///(app-client)/./node_modules/.pnpm/next-auth@4.22.1_next@13.4.3_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:145:35)
Uncaught (in promise) Error: Invariant: Method expects to have requestAsyncStorage, none available
at headers (webpack-internal:///(app-client)/./node_modules/.pnpm/next@13.4.3_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/client/components/headers.js:36:15)
at getServerSession (webpack-internal:///(app-client)/./node_modules/.pnpm/next-auth@4.22.1_next@13.4.3_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/next/index.js:145:35)
The server console seems fine with no erros at all.
- event compiled client and server successfully in 491 ms (2993 modules)
[next-auth][warn][EXPERIMENTAL_API]
`getServerSession` is used in a React Server Component.
https://next-auth.js.org/configuration/nextjs#getServerSession}
https://next-auth.js.org/warnings#EXPERIMENTAL_API
- event compiled client and server successfully in 491 ms (2993 modules)
[next-auth][warn][EXPERIMENTAL_API]
`getServerSession` is used in a React Server Component.
https://next-auth.js.org/configuration/nextjs#getServerSession}
https://next-auth.js.org/warnings#EXPERIMENTAL_API
Could anyone please explain to me what's going on or what I'm implementing wrong?
I
iukea322d ago
Just out of curiosity 5.0 or 5,000?
N
niels322d ago
What do you mean? Might've made a mistake while writing haha. But it raises around 5 thousand errors per second. Hmm I've somehow fixed it. I guess because I was importing this server component into a client component.. read the docs and it said you should give server components as props to client components that worked Now I'm only left with this TS error
'SidebarMobile' cannot be used as a JSX component.
Its return type 'Promise<Element | null>' is not a valid JSX element.
Type 'Promise<Element | null>' is missing the following properties from type 'ReactElement<any, any>': type, props, key
'SidebarMobile' cannot be used as a JSX component.
Its return type 'Promise<Element | null>' is not a valid JSX element.
Type 'Promise<Element | null>' is missing the following properties from type 'ReactElement<any, any>': type, props, key
N
Noobkun322d ago
const SidebarMobile = ({ session }) => {
return session && session.user ? (
<Sheet>
{/* ... */}
</Sheet>
) : null;
};

// Usage in your code
const MyComponent = () => {
const [session, setSession] = useState(null);

useEffect(() => {
const fetchSession = async () => {
const session = await getServerAuthSession();
setSession(session);
};

fetchSession();
}, []);

return (
<div>
{/* ... */}
<SidebarMobile session={session} />
{/* ... */}
</div>
);
};
const SidebarMobile = ({ session }) => {
return session && session.user ? (
<Sheet>
{/* ... */}
</Sheet>
) : null;
};

// Usage in your code
const MyComponent = () => {
const [session, setSession] = useState(null);

useEffect(() => {
const fetchSession = async () => {
const session = await getServerAuthSession();
setSession(session);
};

fetchSession();
}, []);

return (
<div>
{/* ... */}
<SidebarMobile session={session} />
{/* ... */}
</div>
);
};
N
niels322d ago
Defeats the server auth a bit no?
I
iukea322d ago
Not damn
N
Noobkun322d ago
I'm new too ^^' sorry if it wasn't helpfull
N
niels322d ago
Dont worry, I'm no expert either haha
I
iukea322d ago
Bro I am just trying to suck less
N
niels322d ago
Same
L
Liam322d ago
Is this in the app directory or pages directory?
Want results from more Discord servers?
Add your server
More Posts
MySQL GUIThis might be a dumb question, but for those of you on planetscale, what tool do you use to view youWeird error in trpc procedureI am writing a simple create mutation but im getting some weird ts error. I tried restarting the ts 405 Error with S3 Presigned URL'sI currently have a 'PDF viewer' on my website which is suppose to render a PDF from my s3 bucket andunless if want to share components / utils between packages , why we need a mono repo ? T3 cli app ?The T3 Cli have www for the website and a cli , but they dont share any thing in common except the tNeed clerk webhook exampleI have been trying to configure a webhook to be called as soon an organization has been created and GitHub Action Failing Type-Checks but Working LocallyI'm setting up an automatic github action that will run type checks on my nextjs app when pushed / plooking for some tutorialscoming from a rails background, im new to node & t3 in general, is there a tutorial i can follow to is it worth it to have meaningful errors returned from server side form validation?like is it worth it at that point to return an error for every field that is invalid from the backenGood setup for CRA + Serverless in a monorepo?Hey folks, what’s a good setup for a serverless function and a CRA in a monorepo? If I’m able to stHow to redirect with new headers back to the same page?User goes to page `/foo`, we check if this page is protected, if it is, we rewrite the page to sometThe Edge - what's the pointso as far as i know the edge move a server close as possible to your user right? but then what's thcloudflare R2 in Versel?Has anyone here used R2 in their NextJS app hosted on Versel? Trying to save money on bandwidth WhReact.FC equivalent for RSCIs there a "React.FC" equivalent for React Server Components?How do I use the return type of a function with overloads that will be returned in the same functionI'm creating a library, but I have a problem when I use a function with overloads to return itself iMedia not rendering on first try, only after a refreshHey, first of all, this is my first complex Next.js project, so it is very probable that I am doing any good resource for browser extension development?just titleRoute Guarding with nextjsHow do you implement route guarding with nextjs? Not too sure what would be the recommended way to dthe URL must start with the protocol `mongo`I have been geting this error recently, and I have no idea why. my mongodb DATABASE_URL is without "Read and Write in Next Js Is not working in production (vercel)this code is working in local environment but not working in production can anyone tell me how to reDesperate for help with Trpc resolver.How can i get resolve({ default: base64Data }); to only trigger once trpc has returned success or f