<SignOutButton>
The <SignOutButton> component is a button that signs a user out. By default, it is a <button> tag that says Sign Out, but it is completely customizable by passing children.
<SignOutButton> properties
| Name | Type | Description |
|---|---|---|
redirectUrl? | string | Full URL or path to navigate to after signing out. |
signOutOptions? | SignOutOptions | Options for signing out. Includes sessionId which if passed, signs the user out of a specific session. Useful for multi-session applications. |
children? | React.ReactNode | Children you want to wrap the <SignOutButton> in. |
SignOutOptions
The type of the signOutOptions prop for the <SignOutButton> component is defined as follows:
| Name | Type | Description |
|---|---|---|
sessionId? | string | The ID of a specific session to sign out of. Useful for multi-session applications. |
redirectUrl? | string | Full URL or path to navigate to after signing out. |
How to use the <SignOutButton> component
Basic usage
app/page.jsimport { SignOutButton } from "@clerk/nextjs"; export default function Home() { return ( <div> <SignOutButton /> </div> ); }
pages/index.jsimport { SignOutButton } from "@clerk/nextjs"; export default function Home() { return ( <div> <SignOutButton /> </div> ); }
example.jsimport { SignOutButton } from "@clerk/clerk-react"; export default function Example() { return ( <div> <SignOutButton /> </div> ); }
pages/index.jsimport { SignOutButton } from "@clerk/remix"; export default function Home() { return ( <div> <SignOutButton /> </div> ); }
pages/index.jsimport { SignOutButton } from "gatsby-plugin-clerk"; export default function Home() { return ( <div> <SignOutButton /> </div> ); }
Custom usage
You can create a custom button by wrapping your own button, or button text, in the <SignOutButton> component.
app/page.jsimport { SignOutButton } from "@clerk/nextjs"; export default function Home() { return ( <div> <SignOutButton> <button>Sign out</button> </SignOutButton> </div> ); }
pages/index.jsimport { SignOutButton } from "@clerk/nextjs"; export default function Home() { return ( <div> <SignOutButton> <button>Sign out</button> </SignOutButton> </div> ); }
example.jsimport { SignOutButton } from "@clerk/clerk-react"; export default function Example() { return ( <div> <SignOutButton> <button>Sign out</button> </SignOutButton> </div> ); }
pages/index.jsimport { SignOutButton } from "@clerk/remix"; export default function Home() { return ( <div> <SignOutButton> <button>Sign out</button> </SignOutButton> </div> ); }
pages/index.jsimport { SignOutButton } from "gatsby-plugin-clerk"; export default function Home() { return ( <div> <SignOutButton> <button>Sign out</button> </SignOutButton> </div> ); }
Multi-session usage
Sign out of all sessions
Clicking the <SignOutButton> component signs the user out of all sessions. This is the default behavior.
Sign out of a specific session
You can sign out of a specific session by passing in a sessionId to the signOutOptions prop. This is useful for signing a single account out of a multi-session (multiple account) application.
In the example below, the sessionId is retrieved from the useAuth() hook. If the user is not signed in, the sessionId will be null, and the user is shown the <SignInButton> component. If the user is signed in, the user is shown the <SignOutButton> component, which when clicked, signs the user out of that specific session.
app/page.tsx"use client" import { SignInButton, SignOutButton, useAuth } from "@clerk/nextjs"; export default function Home() { const { sessionId } = useAuth(); if (!sessionId) { return ( <div> <SignInButton /> </div> ); } return ( <div> <SignOutButton signOutOptions={{ sessionId }} /> </div> ); }
pages/index.tsximport { SignInButton, SignOutButton, useAuth } from "@clerk/nextjs"; export default function Home() { const { sessionId } = useAuth(); if (!sessionId) { return ( <div> <SignInButton /> </div> ); } return ( <div> <SignOutButton signOutOptions={{ sessionId }} /> </div> ); }
example.jsimport { SignInButton, SignOutButton, useAuth } from "@clerk/clerk-react"; export default function Home() { const { sessionId } = useAuth(); if (!sessionId) { return ( <div> <SignInButton /> </div> ); } return ( <div> <SignOutButton signOutOptions={{ sessionId }} /> </div> ); }
pages/index.jsimport { SignInButton, SignOutButton, useAuth } from "@clerk/remix"; export default function Home() { const { sessionId } = useAuth(); if (!sessionId) { return ( <div> <SignInButton /> </div> ); } return ( <div> <SignOutButton signOutOptions={{ sessionId }} /> </div> ); }
pages/index.jsimport { SignInButton, SignOutButton, useAuth } from "gatsby-plugin-clerk"; export default function Home() { const { sessionId } = useAuth(); if (!sessionId) { return ( <div> <SignInButton /> </div> ); } return ( <div> <SignOutButton signOutOptions={{ sessionId }} /> </div> ); }