(NextJS SSR) How to best check for a logged in user multiple client components deep?
- 0
- Auth
- Web
- Cloud

I have a client component deep in my navbar that needs to change depending on if the user is logged in or not. Using NextJS, I would normally check if user is authenticated from the parent server component like here: https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-4
However, since I need to check for the user many layers deep and update the component whenever the user logs in / logs out, I am at a loss on how to do this, since you cannot use context in a server component.
I thought about importing the getLoggedInUser
function from inside the component and do something like this
const [isLoggedIn, setIsLoggedIn] = useState(false)
useEffect(() => {
const fetchLoggedInUser = async () => {
const user = await getLoggedInUser()
setIsLoggedIn(!!user)
}
fetchLoggedInUser()
}, [])
But this only runs on the first render, and running this e.g. on every route change seems very inefficient. How would you do this?
Recommended threads
- Domain Verification failed
I think i did the step by step well but just not work. When I enter the page I have this error: `Requested host does not match any Subject Alternative Names (S...
- Adding custom domain to Appwrite project
My app is hosted on Vercel on domain todo.velleb.com. On PC, the OAuth logins like GitHub, Discord and Google work and create the account and log in. On mobile ...
- Auth ( OTP Session )
Hi, i would like to ask about OTP session login, may i know is it doable for dynamic/variable for sender,reply-to or not?
