Hello
Is there any way that i can get all the Permissions values on the frontend for a the currently logged in users role from the Session?
Use - Case:
import Session from "supertokens-web-js/recipe/session";
import {
UserRoleClaim,
PermissionClaim,
} from "supertokens-web-js/recipe/userroles";
I tried to create function
async function shouldLoadPageLink(permission) {
if (await Session.doesSessionExist()) {
let validationErrors = await Session.validateClaims({
overrideGlobalClaimValidators: (globalValidators) =>
[...globalValidators,
// UserRoleClaim.validators.includes("admin"),
PermissionClaim.validators.includes(permission)
]
});
if (validationErrors.length === 0) {
// user is an admin
console.log(true)
return true;
}
for (const err of validationErrors) {
if (err.validatorId === UserRoleClaim.id) {
console.log(err)
// user roles claim check failed
} else {
// some other claim check failed (from the global validators list)
console.log(err)
}
}
}
return false
}
I wanted my function to check if the user has permiision (say - 'logs:read') and then show a nav link