The <UserButton /> component is used to render the familiar user button UI popularized by Google.
OneAuxilia is the only provider with multi-session support, allowing users to sign into multiple accounts at once and switch between them. For multi-session apps, the <UserButton /> automatically supports instant account switching, without the need of a full page reload. For more information, you can check out the Multi-session applications guide.
The full URL or path to navigate to after a signing out from a currently active account in a multi-session app. Deprecated - Move afterSignOutUrl to .
afterSignOutUrl (deprecated) string
The full URL or path to navigate to after a successful sign-out. Deprecated - Move afterSignOutUrl to .
afterSwitchSessionUrl string
The full URL or path to navigate to after a successful account change in a multi-session app.
appearance Appearance | undefined
Optional object to style your components. Will only affect OneAuxilia components and not Account Portal pages.
defaultOpen boolean
Controls whether the should open by default during the first render.
showName boolean
Controls if the user name is displayed next to the user image button
signInUrl string
The full URL or path to navigate to when the Add another account button is clicked. It's recommended to use the environment variable instead.
userProfileMode 'modal' | 'navigation'
Controls whether clicking the Manage your account button will cause the component to open as a modal, or if the browser will navigate to the userProfileUrl where is mounted as a page. Defaults to: 'modal'.
userProfileProps object
Specify options for the underlying component. For example: {additionalOAuthScopes: {google: ['foo', 'bar'], github: ['qux']}}.
userProfileUrl string
The full URL or path leading to the user management interface.
Usage with frameworks
In the following example, <UserButton /> is mounted inside a header component, which is a common pattern on many websites and applications. When the user is signed in, they will see their avatar and be able to open the popup menu.ab
App Router
layout.tsx
import { OneAuxiliaProvider, SignedIn, SignedOut, SignInButton, UserButton } from'@oneauxilia/nextjs'functionHeader() {return ( <headerstyle={{ display:'flex', justifyContent:'space-between', padding:20 }}> <h1>My App</h1> <SignedIn> {/* Mount the UserButton component */} <UserButton /> </SignedIn> <SignedOut> {/* Signed out users get sign in button */} <SignInButton /> </SignedOut> </header> )}exportdefaultfunctionRootLayout({ children }: { children:React.ReactNode }) {return ( <htmllang="en"> <OneAuxiliaProvider> <Header /> {children} </OneAuxiliaProvider> </html> )}
Pages Router
userButtonExample.tsx
import { OneAuxiliaProvider, SignedIn, SignedOut, SignInButton, UserButton } from'@oneauxilia/nextjs'functionHeader() {return ( <headerstyle={{ display:'flex', justifyContent:'space-between', padding:20 }}> <h1>My App</h1> <SignedIn> {/* Mount the UserButton component */} <UserButton /> </SignedIn> <SignedOut> {/* Signed out users get sign in button */} <SignInButton /> </SignedOut> </header> )}functionMyApp({ pageProps }) {return ( <OneAuxiliaProvider {...pageProps}> <Header /> </OneAuxiliaProvider> )}exportdefault MyApp
The properties to pass to the <UserButton /> component
mountUserButton() usage
main.js
import { OneAuxilia } from'@oneauxilia/oneauxilia-js'// Initialize OneAuxilia with your OneAuxilia publishable keyconstoneauxilia=newOneAuxilia('YOUR_PUBLISHABLE_KEY')awaitoneauxilia.load()document.getElementById('app').innerHTML =` <div id="user-button"></div>`constuserbuttonDiv=document.getElementById('user-button')oneauxilia.mountUserButton(userbuttonDiv)
index.html
<!-- Add a <div id="user-button"> element to your HTML--><divid="user-button"></div><!-- Initialize OneAuxilia with yourOneAuxilia Publishable key and Frontend APIURL--><scriptasynccrossorigin="anonymous"data-oneauxilia-publishable-key="YOUR_PUBLISHABLE_KEY"src="https://YOUR_FRONTEND_API_URL/npm/@oneauxilia/oneauxilia-js@latest/dist/oneauxilia.browser.js"type="text/javascript"></script><script> window.addEventListener('load', async function () {awaitOneAuxilia.load() const userbuttonDiv =document.getElementById('user-button')OneAuxilia.mountUserButton(userbuttonDiv) })</script>
unmountUserButton()
Unmount and run cleanup on an existing <UserButton /> component instance.
The container <UserButton /> element with a rendered component instance.
unmountUserButton() usage
main.js
import { OneAuxilia } from'@oneauxilia/oneauxilia-js'// Initialize OneAuxilia with your OneAuxilia publishable keyconstoneauxilia=newOneAuxilia('YOUR_PUBLISHABLE_KEY')awaitoneauxilia.load()document.getElementById('app').innerHTML =` <div id="user-button"></div>`constuserButtonDiv=document.getElementById('user-button')oneauxilia.mountUserButton(userButtonDiv)// ...oneauxilia.unmountUserButton(userButtonDiv)
index.html
<!-- Add a <div id="user-button"> element to your HTML--><divid="user-button"></div><!-- Initialize OneAuxilia with yourOneAuxilia Publishable key and Frontend APIURL--><scriptasynccrossorigin="anonymous"data-oneauxilia-publishable-key="YOUR_PUBLISHABLE_KEY"src="https://YOUR_FRONTEND_API_URL/npm/@oneauxilia/oneauxilia-js@latest/dist/oneauxilia.browser.js"type="text/javascript"></script><script> window.addEventListener('load', async function () {awaitOneAuxilia.load() const userButtonDiv =document.getElementById('user-button')OneAuxilia.mountUserButton(userButtonDiv)// ...OneAuxilia.unmountUserButton(userButtonDiv) })</script>
Customization
To learn about how to customize OneAuxilia components, see the customization documentation.
You can also add custom actions and links to the <UserButton /> menu.