Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Kinde · Function

getRoles

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.

How it works

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.

Syntax

getRoles = async (): Promise<Role[]>

Returns

Promise<Role[]>

Key points

  • Use getRoles to obtain the roles belonging to the currently authenticated user.
  • Its asynchronous signature resolves to an array of Role values.
  • The function is intended for reading user roles, not changing role assignments.
  • Await the call before using the returned collection.
  • A returned role object includes an id field.

Common mistakes

  • The roles claim is optional, so enable roles in the application settings before expecting getRoles to return them.

Example: Read the current user's roles

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.

When to use it

Role-aware UI

Render or tailor application behavior based on the authenticated user's assigned roles.

Client-side access checks

Check whether the current user has a role before allowing role-dependent application actions.

Display role information

Inspect role metadata such as IDs, keys, and names for account context.

Interview questions

QWhat does getRoles return?

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.

QHow do you call getRoles?

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.

QWhy might getRoles not provide the expected roles?

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.

  • getUserProfile
  • getFlag
  • Role

Source: Expo. Checked 2026-10-15.