useSession() from NextAuth fails
Answered
Gull Dong posted this in #help-forum
Gull DongOP
I am trying to return the session: Session object from within my function, however, I keep getting the rule of hooks error.
Answered by Alfonsus Ardani
use getServerSession if you want to get it from the server
32 Replies
where are you using Token function
Gull DongOP
in a file
Gull DongOP
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^
rename Token to useToken
Gull DongOP
did that and got same error
ok let me see where you are using your Token function
Gull DongOP
you cant do that
Gull DongOP
why nawt
because rule of hooks
Gull DongOP
i dont get which rule im breaking tho
you can't use hooks outside of a react component
Gull DongOP
nextauth also doesnt let you return user's session in server call so oh well
use getServerSession if you want to get it from the server
Answer
but oh well
Gull DongOP
getserversession only returns boolean no?
idk where you get that from
Gull DongOP
the website o_o
oh but you need a request
you can just pass in the authOption on the first parameter, no need request or response, those are for
pages
dirGull DongOP
oh okay
Gull DongOP
does calling
getServerSession()
return the same object as useSession()
?it has minor differences but yes it should return the same crucial data
Gull DongOP
well now im just getting a freaking loader issue
even tho i changed none of my packages
But using it inside a react component works right?
Gull DongOP
yeah i got the session
also that using getServerSession() in Server Component works right?
Gull DongOP
can you resolve the post
allright thanks