Difference between useSession and getSession in next-auth?
Asked Answered
S

1

11

What's the difference between useSession and getSession in next-auth? Both seems to be returning session object.

Sacristan answered 18/9, 2021 at 11:20 Comment(1)
For a more complete answer: #77094115Rep
K
16

useSession ReactJS hook that works only on client, that returns states which helps you to update UI and it's made on top of getSession

getSession async function that read current cookies and returns session, works both on Client and Server

Kroeger answered 18/9, 2021 at 11:28 Comment(3)
And what about getSession vs getServerSession ?Embowed
@RobinvanBaalen you can protect server side rendered pages using the getServerSession method. This is different from the old getSession() method, in that it does not do an extra fetch out over the internet to confirm data from itself, increasing performance significantly. You need to add this to every server rendered page you want to protect. Be aware, getServerSession takes slightly different arguments than the method it is replacing, getSession. Check this linkDahabeah
For a more complete answer: #77094115Rep

© 2022 - 2024 — McMap. All rights reserved.