P粉9669797652023-09-04 23:19:18
I think I've solved this problem, I decided to forget about _app.js and put everything in my custom layout.js file. I still need to test if the user will stay logged in since header.js is outside of layout.js.
How I solved it: I added
'use client' import { SessionProvider } from "next-auth/react";
Go to layout.js
(the file that comes with Next.js by default) and pass the session in the parameter of the function being "exported" (the default function RootLayout is exported). Then I wrapped all return() parameters with .
This is part of the code:
export default function RootLayout({ children, session }) { return ( <html lang="en"> <SessionProvider session={session}> <body>{children}</body> </SessionProvider> </html> ) }
IMPORTANT PART: If you use the 'use client'
option, Next will not allow you to export metadata, so you need to remove < code>export const metadata from your code = {....
UPDATE: For some reason it doesn't work on Vercel (even though it runs locally). I'll try to fix it and update my answer. TL;DR: This solution works locally but does not work when deployed to Vercel.