# Using roles in UI extensions Learn how to include user roles in UI Extensions to tailor functionality to different roles. Stripe Apps UI extensions can read the active user’s role in the Dashboard. Apps can expose different functionality to different user roles. The UI Extension SDK provides valuable information about the end user of your app. The `roles` field of the `userContext` object gives a list of the active user’s roles. You can tailor the app’s content based on the user’s role, using the roles in the user context. In addition to roles, use `appContext.authorizedPermissions` to check which permissions the app has for the current context. For a full list of fields, see `appContext` in the [UI Extension SDK API](https://docs.stripe.com/stripe-apps/reference/extensions-sdk-api.md). ## How to determine the user’s Dashboard role Extensions have a `userContext` prop that’s populated with information about the active Dashboard user. This object has a `roles` field, which is an array of `RoleDefinition` objects for each role that the active user is attributed to. A role definition has these fields: | Field name | Type | Example | | ---------- | -------------------- | --------- | | type | ‘builtIn’ | ‘custom’ | builtIn | Specifies the role type. Custom roles are only available to [private apps](https://docs.stripe.com/stripe-apps/distribution-options.md#share-with-team-members). | | id | string | developer | A stable, machine-readable identifier for the user role. Unlike `name`, this value won’t change when role display names are updated and is safe to use for comparisons. | | name | string | Developer | Plain language name for the user role. Use `id` for programmatic comparisons because the `name` can change. | The `id` field provides a stable identifier for the user role that you can use to modify your UI extension’s functionality. Use `id` instead of `name` for programmatic role comparisons to prevent breakages if the role display names change. ## Custom user roles (private apps only) Each role definition has a type field, which specifies the role type. The type field can either be ‘builtIn’ or ‘custom’. Because custom roles are specific to a given account, these roles are only available for private apps. ## Tailoring content based on the Dashboard role A common use of this information is to conditionally display content based on the user role. Below is an example app that shows content tailored to particular user roles. ```tsx import { Badge, Box, Inline, ContextView } from "@stripe/ui-extension-sdk/ui"; import type { ExtensionContextValue } from "@stripe/ui-extension-sdk/context"; const App = ({ userContext }: ExtensionContextValue) => { // Use `id` for stable role comparisons instead of `name` const isAdmin = userContext?.roles?.some(role => role.id === 'admin'); const isDeveloper = !isAdmin && userContext?.roles?.some(role => role.id === 'developer'); const isAnotherRole = !isDeveloper && !isAdmin; return ( Active user roles: {userContext?.roles?.map(role => {role.name})} { isAdmin && (Only admin users can see this message.) } { isDeveloper && (Only developers users can see this message.) } { isaAnotherRole && (Only users who are not admins or developers can see this message.) } ); }; export default App; ``` ![A screenshot of the result of the example code above for an Administrator user](https://b.stripecdn.com/docs-statics-srv/assets/roles-example.7fb1048ac4656aee8a39a33d9179ad26.png) The result of the example app when viewing the app as an Administrator user ## See also - [Build a UI](https://docs.stripe.com/stripe-apps/build-ui.md) - [UI Extension SDK API reference](https://docs.stripe.com/stripe-apps/reference/extensions-sdk-api.md) - [User roles](https://docs.stripe.com/get-started/account/teams/roles.md)