#Initial state loading

33 messages · Page 1 of 1 (latest)

main galleon
#

I make a simple app with posts. I have my own backend. How to implement initial fetching information about current user, like sending request for validating jwt. I think making it in every component is a bad idea. as a state manager I use zustand. I think it's a good practice to store user object in zustand store, isn't it?

median vectorBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

azure isle
main galleon
azure isle
#

where is currently the problem? To get the jwt? To auth the user? To create the login form? ...

main galleon
#

So I can't fetch current user in server componenet

azure isle
#

Which library do you use to auth the user?

main galleon
#

So I do auth with http requests to it

azure isle
#

ah ok. Set the important keys as cookie and then access the cookies on your server component and fetch the user serverside

main galleon
azure isle
#

and?

main galleon
#

I want to do so

azure isle
#

yea, you can do so

main galleon
#

so what's the common way to do that with jwt in localstorage

azure isle
#

exactly like I told you

Set the important keys as cookie and then access the cookies on your server component and fetch the user serverside

main galleon
#

ok, thanks

#

But also I wanna know what's the best way to implement it without server components

azure isle
#

without? 🤔
In nextjs? If you want to do everything without, that you should use react ^^

main galleon
#

yep

#

and how do they implement it in pure react?

main galleon
#

yes but where should I make this request

#

in every component?

azure isle
#

to get the user or to auth your user?

main galleon
#

to get it

#

that's what I was interested in

azure isle
#

ah, you can do it in a middleware or in every comp.

#

Or maybe inside a layout as comp

main galleon
#

ok, thanks

azure isle