Hello everyone ! I'm building a react app, and lea...
# ask-a-descoper
a
Hello everyone ! I'm building a react app, and learning everything at the same time 😅 I wonder if, once I define 4 roles, I can set a route to a specific homepage for each ? And also, if the options in the general menu can differ ? Thanks in advance if you can help clear my mind about this (I didn't find the info in the documentation, that I almost extensively read before posting here !) Joe
s
when you say "specific homepage for each" , you mean a diff flow screen for each role ? or diff app homepage for each role ?
a
Hello Meir ! Thanks for your answer ! The "homepage" I'm talking about would be an entry point: the student accesses the exercises directly and can add a bit of infos to his profile; the teacher can also use the exercises, but his homepage would rather be a dashboard to see the progression of his students; the referent would also have a dashboard, that would include the teachers he's responsible of, and the ability to view the students' progression. And finally, the admin dashboard for me. That's where I don't get it yet, I was thinking about different homepages for those purposes, but I'm not sure that the authorizations are intended to do that (except maybe by forbidding access to specific react modules ?)
s
you can put roles on users in frontend, show the right page/view according to role , see here https://github.com/descope/react-sdk#helper-functions in backend, validate you enforce the roles can't access resources they are forbidden from https://docs.descope.com/build/guides/session/#logout-all-sessions-using-backend-sdk
👀 1
@dazzling-oyster-96577 do you have some good example with React for this one ?
a
Thank you very much ! I'm going to investigate & learn (and maybe make up my mind soon about using the react sdk or the python one !)
https://github.com/descope/react-sdk#helper-functions I saw this while reading the doc, but didn't notice particularly because there was no mention of a "route", or specific destination linked to a role... As you can see, I still have to discover the implicit links between various parts of the system I just set up 😅 I'm going to dig deeper with the help of my bot/tutor/codewriter. Thanks again ! 👍
s
Joe, Essentially, you can: 1. Log the user in 2. Validate the role for the user,
Copy code
const roles=["myRole"]

// Return value : Boolean (true or false)
try {
    const isRoleValid =  descopeClient.validateRoles(authInfo, roles);
    if (isRoleValid) {
        console.log("These roles are valid for user")
        // Direct the user to the applicable page
    } else {
        console.log("These roles are invalid for user")
    }
} catch (error) {
    console.log ("Could not confirm if roles are valid - error prior to confirmation. " + error);
}
👍 1
👍🏼 1
a
Thank you Chris ! I will try this !
s
Let us know how it goes and if you have any further questions.
👍 1