Role-aware UI
Render or tailor application behavior based on the authenticated user's assigned roles.
Kinde · Function
getRoles asynchronously returns the current user's roles as an array of Role objects. It requires the roles claim to be enabled in the application's token settings.
Call getRoles to asynchronously retrieve the roles associated with the current user. The result is an array of Role objects; roles must be included in the token through the application's settings for this information to be available.
getRoles = async (): Promise<Role[]>Promise<Role[]>
import { getRoles } from "@kinde/expo/utils";
const roles = await getRoles();
console.log(roles);Fetches the current user's roles and logs the returned role objects.
Render or tailor application behavior based on the authenticated user's assigned roles.
Check whether the current user has a role before allowing role-dependent application actions.
Inspect role metadata such as IDs, keys, and names for account context.
getRoles is an asynchronous utility that returns a Promise resolving to an array of Role objects. Each role can include fields such as id, key, and name.
Follow-up: What must be configured if the returned roles are missing? Enable the roles claim in the application's token settings.
The function is called without arguments: await getRoles(). It reads the current user's roles from the available authentication token.
Follow-up: How would you handle the result safely? Await it inside an async flow and treat the result as a collection that may be empty.
Roles are not guaranteed to be present because they are optional in the token. The application must be configured to add the roles claim before the function can use it.
Follow-up: What should authorization code do when no roles are returned? Deny role-dependent access rather than assuming a default privileged role.
getUserProfilegetFlagRole