Signing out ends the session in this browser. With Better Auth it’s one call, authClient.signOut(), and any part of the page that shows the session updates by itself. This guide adds a Better Auth sign-out button to a Next.js app and shows the result.
The short answer: call authClient.signOut() from a button in a client component. Better Auth ends the session, and useSession switches to signed out.
Syntax
await authClient.signOut({
fetchOptions: {
onSuccess: () => {
// for example, open the sign-in page
},
},
});
authClient.signOut()ends the current session. The options are optional.fetchOptions.onSuccess: code to run once the session has ended, such as opening another page.
The reference: Signout (opens in a new tab) in the Better Auth documentation.
Prerequisites
- a Next.js app with Better Auth’s client (
createAuthClientfrombetter-auth/react) and a way to sign in
Step 1: Add a Sign Out Button
The example is a small bookshop app. Its header shows who’s signed in, so that’s where the button goes. Create components/user-menu.tsx:
"use client";
import Link from "next/link";
import { authClient } from "@/lib/auth-client";
export function UserMenu() {
const { data: session, isPending } = authClient.useSession();
if (isPending) {
return null;
}
if (!session) {
return (
<nav className="flex gap-4 text-sm">
<Link href="/sign-in">Sign in</Link>
<Link href="/sign-up">Sign up</Link>
</nav>
);
}
return (
<div className="flex items-center gap-4 text-sm">
<span>Signed in as {session.user.name}</span>
<button
type="button"
onClick={() => authClient.signOut()}
className="rounded border border-zinc-300 px-3 py-1 dark:border-zinc-700"
>
Sign out
</button>
</div>
);
}
- The button’s
onClickcallsauthClient.signOut(). authClient.useSession()notices the change, so the menu switches to the Sign in and Sign up links without any other code.
Put <UserMenu /> in your layout’s header, so it’s on every page.
Step 2: Sign Out
Sign in, and the header shows the name and the button:

Click Sign out. The header switches back to the links:

Better Auth deletes this browser’s session from the database. Sessions on the person’s other devices stay signed in.
FAQ
How do I open another page after signing out?
Pass fetchOptions.onSuccess, as in the Syntax section, and open the page there, for example with Next.js’s router.push.
How do I sign someone out on every device?
Better Auth’s revokeSessions ends all of the person’s sessions (Revoke All Sessions (opens in a new tab)). Part 5 of the Better Auth Tutorial covers sessions.
Conclusion
authClient.signOut() ends the session in this browser, and everything that reads the session with useSession updates by itself.
Additional Resources
- Signout (opens in a new tab) in the Better Auth documentation
- Session management (opens in a new tab)
Related
- Better Auth Tutorial — Part 3: Sign Up and Sign In with Email and Password, where this is one step of the full setup
Better Auth, Next.js and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by Better Auth, Inc. or Vercel.
0 comments