#Global state management and database auth

11 messages · Page 1 of 1 (latest)

solemn tree
#

Hey folks

Came here to ask a question. I am doing a next.js project where I will have users that have perms and a role. I have Lucia and lucia's getUser function that checks and validates all the sessions and other things and returns a user if everything's fine. Every user will have the role, some IDs and a permissions array, with perms like 'canSeeX'. I am thinking about using zustand for global state management so upon logging in and validating the user, I could set a global state with the role, ID and the perms to easily show and hide certain things. For example if the user has no admin role, I would hide buttons like admin panel based on the state and user object. I validate the user anyways on the server side each time they do something so I think it should be a safe solution, even if somebody was nosy it won't hurt if they enter /admin route manually since they won't get anything from the DB.

Is this a valid approach, or did I get it completely wrong?

glad ospreyBOT
#

🔎 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)

solemn tree
#

b

#

Global state management and database auth

solemn tree
#

b

solemn tree
#

b

round veldt
#

I think that's fine @solemn tree

#

as long as you have authentication and authorization on the backend

#

you can use your global states for client-end side authorization or anything you want

solemn tree
round veldt
#

You can close the thread then