Add custom pages and links to the <UserProfile />
component
The <UserProfile />
component supports the addition of custom pages and use of external links in the navigation sidebar.
There are two ways to render the <UserProfile />
component:
- As a modal
- As a dedicated page
Both can be accessed when the user selects the <UserButton />
, and then selects the Manage account option.
This guide includes examples for both use cases. You can select one of the following two tabs on the code examples to see the implementation for your preferred use case:
<UserButton />
tab: By default, the<UserButton />
setsuserProfileMode='modal'
. If you are using the default settings, then you should select this tab.Dedicated page
tab: If you do not want the<UserProfile />
to open as a modal, then you should select this tab. For these examples, you need to setuserProfileMode='navigation'
anduserProfileUrl='/user-profile'
on the<UserButton />
component.
Add a custom page to <UserProfile />
Custom pages can be rendered inside the <UserProfile />
component and provide a way to incorporate app-specific settings or additional functionality.
To add a custom page to the <UserProfile />
component, use the <UserButton.UserProfilePage />
component or the <UserProfile.Page />
component, depending on your use case.
Props
<UserButton.UserProfilePage />
and <UserProfile.Page />
accept the following props, all of which are required:
- Name
label
- Type
string
- Description
The name that will be displayed in the navigation sidebar for the custom page.
- Name
labelIcon
- Type
React.ReactElement
- Description
An icon displayed next to the label in the navigation sidebar.
- Name
url
- Type
string
- Description
The path segment that will be used to navigate to the custom page. For example, if the
<UserProfile />
component is rendered at/user
, then the custom page will be accessed at/user/{url}
when using path routing.
- Name
children
- Type
React.ReactElement
- Description
The components to be rendered as content inside the custom page.
Example
The following example demonstrates two ways that you can render content in the <UserButton.UserProfilePage />
or <UserProfile.Page />
component: as a component or as a direct child.
JavaScript example
To add custom pages to the <UserProfile />
component using the JavaScript SDK, you can pass the customPages
property to the mountUserProfile()
or openUserProfile()
method, as shown in the following example:
Add a custom link to <UserProfile />
You can add external links to the <UserProfile />
navigation sidebar using the <UserButton.UserProfileLink />
component or the <UserProfile.Link />
component, depending on your use case.
Props
<UserButton.UserProfileLink />
and <UserProfile.Link />
accept the following props, all of which are required:
- Name
label
- Type
string
- Description
The name that will be displayed in the navigation sidebar for the link.
- Name
labelIcon
- Type
React.ReactElement
- Description
An icon displayed next to the label in the navigation sidebar.
- Name
url
- Type
string
- Description
The absolute or relative url to navigate to
Example
The following example adds a link to the homepage in the navigation sidebar of the <UserProfile />
component.
Reorder default routes
If you want to reorder the default routes, Account
and Security
, set the label
prop to 'account'
or 'security'
. This will target the existing default page and allow you to rearrange it.
Note that when reordering default routes, the first item in the navigation sidebar cannot be a <UserButton.UserProfileLink />
or <UserProfile.Link />
component.
The first page in the list will always be rendered under the root path defined with the path
prop. Its url
prop will be ignored.
In the following example, path
is set to /user-profile
, so the <CustomPage />
is rendered under the /user-profile
path.
The first page in the list will always be rendered under the root path defined with the path
prop. Its url
prop will be ignored.
In the following example, path
is set to /user-profile
, so the custom page is rendered under the /user-profile
path.
With the above example, the <UserProfile />
navigation sidebar will be in the following order:
- Custom Page
- Homepage
- Account
- Security
Feedback
Last updated on