#NextAuth authenticating

8 messages · Page 1 of 1 (latest)

untold orbit
#

i am attempting to get the session and check if it exists or not (if they are logged in)
but ive been getting this error even thought i already wrapped it;

error:

Unhandled Runtime Error
Error: [next-auth]: `useSession` must be wrapped in a <SessionProvider />```

page.tsx:
```java
"use client";
import Hero from "@/components/Hero";
import MainNavbar from "@/components/MainNavbar";
import Features from "@/components/Features";
import Footer from "@/components/Footer";
import {SessionProvider, useSession} from "next-auth/react";

export default function Home() {
    const {data: session} = useSession();

    return (

        <SessionProvider session={session}>
            <main className='overflow-hidden'>
                <MainNavbar session={session}/>
                <Hero/>
                <Features></Features>
                <Footer></Footer>
            </main>
        </SessionProvider>

    )
}
sterile wedgeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

stoic thunder
#

the SessionProvider is providing the session to useSession and you're using it in a component which is not wrapped with it

#

it will throw an error

untold orbit
#

so you mean like this?


export default function RootLayout({
                                       children,
                                   }: {
    children: React.ReactNode
}) {
    return (
        <SessionProvider>
        <html lang="en">
        <body className={inter.className}>
        {children}
        </body>
        </html>
        </SessionProvider>
    )
}```
untold orbit
#

nevermind i solved it