cabara
08/02/2023, 4:37 PMUserRoleClaim
. Is there a way to allow users with ANY of the given roles to a route? For example, how should I set the validator so that users with any one of the roles admin, subadmin, subsubadmin
are given access to a certain route?
Thank you.rp_st
08/02/2023, 5:22 PMrp_st
08/02/2023, 5:23 PMapp.post("/update-blog", verifySession(), async (req: SessionRequest, res) => {
const roles = await req.session!.getClaimValue(UserRoles.UserRoleClaim);
if (roles === undefined || !roles.includes("admin")) {
// this error tells SuperTokens to return a 403 to the frontend.
throw new STError({
type: "INVALID_CLAIMS",
message: "User is not an admin",
payload: [{
id: UserRoles.UserRoleClaim.key
}]
})
}
// user is an admin..
});
So you can do something similar.cabara
08/02/2023, 5:27 PMcabara
08/02/2023, 5:28 PM