Next.js Discord

Discord Forum

Best way to access user data from nested components

Unanswered
Expensiveee posted this in #help-forum
Open in Discord
Hello guys, I'm using supabase + nextjs@15 I was wondering what would be the best way to access user data from anywhere in my app.

I'm not talking about supabase.auth.getUser(), I have a users table that I want to access

I want it to be efficient and not making calls to db at each page chage (if possible)

Maybe a context, a hook, smth in the middlware.ts.

I have no idea what the standard is

3 Replies

I thoutgh about using SWR and creating a /me route that returns the data, so I can make a simple useUser hook, but is it really the way to go?
@Expensiveee Hello guys, I'm using supabase + nextjs@15 I was wondering what would be the best way to access user data from anywhere in my app. I'm not talking about supabase.auth.getUser(), I have a users table that I want to access I want it to be efficient and not making calls to db at each page chage (if possible) Maybe a context, a hook, smth in the middlware.ts. I have no idea what the standard is
normally you save the most important details from your table inside a local jwt. This jwt can then be accessed via the browser or the server (everywhere). I like to use next-auth for my auth and can get my jwt information via a await getServerSession(authOptions) and when on clientside I can use the hook useSession to retrieve the information. You are using supabase. Maybe there is something similar to that
@Expensiveee solved?