#useSession() from NextAuth fails

34 messages · Page 1 of 1 (latest)

young lily
#

I am trying to return the session: Session object from within my function, however, I keep getting the rule of hooks error.

forest totemBOT
#

🔎 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)

wintry siren
#

where are you using Token function

young lily
#

in a file

wintry siren
young lily
#

lol im trying to export it as a module

#

i could also just import a function that runs the checks im trying to run but i wanted to test this^

wintry siren
#

rename Token to useToken

young lily
#

did that and got same error

wintry siren
#

ok let me see where you are using your Token function

young lily
wintry siren
#

you cant do that

young lily
#

why nawt

wintry siren
#

because rule of hooks

young lily
#

i dont get which rule im breaking tho

wintry siren
#

you can't use hooks outside of a react component

young lily
#

nextauth also doesnt let you return user's session in server call so oh well

wintry siren
#

use getServerSession if you want to get it from the server

#

but oh well

young lily
#

getserversession only returns boolean no?

wintry siren
#

idk where you get that from

young lily
#

the website o_o

#

oh but you need a request

wintry siren
#

you can just pass in the authOption on the first parameter, no need request or response, those are for pages dir

young lily
#

oh okay

#

does calling getServerSession() return the same object as useSession()?

wintry siren
#

it has minor differences but yes it should return the same crucial data

young lily
#

well now im just getting a freaking loader issue

#

even tho i changed none of my packages

wintry siren
#

But using it inside a react component works right?

young lily
#

yeah i got the session

wintry siren
#

also that using getServerSession() in Server Component works right?

young lily
#

can you resolve the post

wintry siren
#

allright thanks