How do I check if the user is currently authorized or not in client?
Answered
Arcra posted this in #help-forum
ArcraOP
I want to show a logout button if the user is logged in.
I'm using app router and I could not make the component a server component. calling
I'm using app router and I could not make the component a server component. calling
auth() in useEffect gives me error.Answered by B33fb0n3
normally auth libraries also provide ways on how to get the session clientside. If that does not exists, you can pass the session from server to clientside and render it there. Or, even better: you can use SSR to either render a login button or render a log out button.
TL;DR:
1. use a hook to get the session clientside
2. pass data from server to client via props
3. use SSR to render the correct button
TL;DR:
1. use a hook to get the session clientside
2. pass data from server to client via props
3. use SSR to render the correct button
6 Replies
@Arcra I want to show a logout button if the user is logged in.
I'm using app router and I could not make the component a server component. calling `auth()` in `useEffect` gives me error.
normally auth libraries also provide ways on how to get the session clientside. If that does not exists, you can pass the session from server to clientside and render it there. Or, even better: you can use SSR to either render a login button or render a log out button.
TL;DR:
1. use a hook to get the session clientside
2. pass data from server to client via props
3. use SSR to render the correct button
TL;DR:
1. use a hook to get the session clientside
2. pass data from server to client via props
3. use SSR to render the correct button
Answer
ArcraOP
In Auth.js [docs](https://authjs.dev/getting-started/session-management/get-session), I couldn't find anything about app router. I think it is not good to SessionProvider
@Arcra In Auth.js [docs](https://authjs.dev/getting-started/session-management/get-session), I couldn't find anything about app router. I think it is not good to SessionProvider
yea, then do one of the things, that I recommended (https://nextjs-forum.com/post/1268543180786237481#message-1268543582940168202 click)
@Arcra solved?
ArcraOP
I just used SessionProvider which is not recommended, thanks for help
@Arcra I just used SessionProvider which is not recommended, thanks for help
thanks for clarifying that you chose
Happy to help
1.Happy to help