UI Components <SignOutButton> <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.
Name asChild?
Type boolean
Description For Astro only: If true
, the <SignOutButton>
component will render its children as a child of the component.
Name redirectUrl?
Type string
Description The redirect URL to navigate to after sign out is complete.
Name signOutOptions?
Type SignOutOptions
Description Options for signing out. Includes sessionId
which if passed, signs the user out of a specific session. Useful for multi-session applications.
Name children?
Type React.ReactNode
Description Children you want to wrap the <SignOutButton>
in.
The type of the signOutOptions
prop for the <SignOutButton>
component is defined as follows:
Name sessionId?
Type string
Description The ID of a specific session to sign out of. Useful for multi-session applications.
Name redirectUrl?
Type string
Description The redirect URL to navigate to after sign out is complete.
app /page.js import { SignOutButton } from '@clerk/nextjs'
export default function Home () {
return < SignOutButton />
}
example.js import { SignOutButton } from '@clerk/clerk-react'
export default function Example () {
return < SignOutButton />
}
pages /index.js import { SignOutButton } from '@clerk/remix'
export default function Home () {
return < SignOutButton />
}
pages /index.astro ---
import { SignOutButton } from '@clerk/astro/components'
---
< SignOutButton />
pages /index.vue < script setup >
import { SignOutButton } from '@clerk/vue'
</ script >
< template >
< SignOutButton />
</ template >
You can create a custom button by wrapping your own button, or button text, in the <SignOutButton>
component.
app /page.js import { SignOutButton } from '@clerk/nextjs'
export default function Home () {
return (
< SignOutButton >
< button >Custom sign out button</ button >
</ SignOutButton >
)
}
example.js import { SignOutButton } from '@clerk/clerk-react'
export default function Example () {
return (
< SignOutButton >
< button >Custom sign out button</ button >
</ SignOutButton >
)
}
pages /index.js import { SignOutButton } from '@clerk/remix'
export default function Home () {
return (
< SignOutButton >
< button >Custom sign out button</ button >
</ SignOutButton >
)
}
You must pass the asChild
prop to the <SignOutButton>
component if you are passing children to it.
pages /index.astro ---
import { SignOutButton } from '@clerk/astro/components'
---
< SignOutButton asChild >
< button >Custom sign out button</ button >
</ SignOutButton >
example.vue < script setup >
import { SignOutButton } from '@clerk/vue'
</ script >
< template >
< SignOutButton >
< button >Custom sign out button</ button >
</ SignOutButton >
</ template >
Clicking the <SignOutButton>
component signs the user out of all sessions. This is the default behavior.
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 following example, 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 < SignInButton />
}
return < SignOutButton signOutOptions = {{ sessionId }} />
}
example.js import { SignInButton , SignOutButton , useAuth } from '@clerk/clerk-react'
export default function Home () {
const { sessionId } = useAuth ()
if ( ! sessionId) {
return < SignInButton />
}
return < SignOutButton signOutOptions = {{ sessionId }} />
}
pages /index.js import { SignInButton , SignOutButton , useAuth } from '@clerk/remix'
export default function Home () {
const { sessionId } = useAuth ()
if ( ! sessionId) {
return < SignInButton />
}
return < SignOutButton signOutOptions = {{ sessionId }} />
}
example.vue < script setup >
import { SignInButton , SignOutButton , useAuth } from '@clerk/vue'
const { sessionId } = useAuth ()
</ script >
< template >
< SignInButton v-if = "!sessionId" />
< SignOutButton v-else :sign-out-options = "{ sessionId }" />
</ template >
Last updated on Jan 9, 2025