using useSession hook

is it good to call useSession many times or make useSession globally, im still kinda new so need a lot of advice and guidance thanksss
4 Replies
arete
arete2y ago
because i want use dashboard layout that have username and user image and whats the best practice calling useSession
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
amanuel
amanuel2y ago
My stance on this depends on what your purpose is for the usage. For instance, if all you need to do is protect the page from unauthorized access, then do something like this in get getServerSideProps:
const session = await unstable_getServerSession(req, res, authOptions);

if (!session || !session.user) {
return {
redirect: {
destination: "/sign-in",
permanent: false,
},
};
}
const session = await unstable_getServerSession(req, res, authOptions);

if (!session || !session.user) {
return {
redirect: {
destination: "/sign-in",
permanent: false,
},
};
}
arete
arete2y ago
i think this can clear my worry about useSession thanks @Psych0F0x @amanuel
Want results from more Discord servers?
Add your server