Next.js Discord

Discord Forum

Need some help using supabase

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Hi there! I'd be happy to help you revise your text for any grammatical errors. Here's the revised version:

"Hi there! I am learning Next.js by myself and I have started a small project. I am authenticating users with the GitHub provider. However, I want to have a user avatar with a dropdown menu on my navbar when a user is authenticated, and display a login and sign-in button if they are not. I am currently stuck on this part. How can I retrieve the user information in a client component?

The navbar is in layout.tsx, so I believe I cannot fetch data directly in it, right? Therefore, I can't have a server component parent and pass down the data. Any help would be greatly appreciated. 😔

20 Replies

Chinese Egret
You could get the user information from a server component also or why could you not? Is the layout a client component?
@Chinese Egret You could get the user information from a server component also or why could you not? Is the layout a client component?
Sun bearOP
I mean I don’t know if is ok to retrieve the user on the root layout and pass down
@Sun bear I mean I don’t know if is ok to retrieve the user on the root layout and pass down
My brain might be not braining rn but it should be fine
Chinese Egret
You can, but I would recommend retreiving the data in a server component like user navbar etc.
Are there hooks?
Probably not
@Chinese Egret You can, but I would recommend retreiving the data in a server component like user navbar etc.
Sun bearOP
So I could use a server component that wraps the client one and there retrieve the user right?
U can use server actions
@Clown My brain might be not braining rn but it should be fine
Sun bearOP
Yeah but I swear that I read on some place that on the root layout isn’t fine to do this kind of stuff
Other way would be to use route handlers when working with client side or fetching in server components and prop drilling.
Chinese Egret
The problem doing it in layout component is that the page wont render until the data is there
But again, i dont know how you will do the prop drilling and stuff
And at that point its better to just use a context.
Chinese Egret
So retrieving where you need it for me is better, then use Suspense
@Clown And at that point its better to just use a context.
Sun bearOP
There is not prop drilling because I only need it in profile navbar button
Then just fetch where you need to use it
✊👍
Sun bearOP
Thanks for your time I will try your suggestions @Clown @Chinese Egret