useUser and page flashing

Hello.
I am using Supabase with Next.js
I've created a navbar in my pagelayout component.
Based on whether the user has signedin (there is session) I want to show an "account menu".
The go-to solution for this seems to be the useUser() hook from the react auth helpers.
So, I use the user to check if a user exists and then go with user ? <AccountMenu> : <SignInButton>
The problem is that the page flashes instantly with the sign in button before showing the <AccountMenu> component.
Also, when changes between pages that use the same page layout the state doesn't persist and the flashing happens on every page.
How would be the way to go about it without getting the flashing?
Also, if I wanted to bring in some user data as well (name, avatar) what would be the way to do it and not request it for every page change?

Thanks
Was this page helpful?