useCapxulSignOut
Mutation hook for ending the current session and clearing cached signed-in state.
Ends the current session. The counterpart to
useCapxulSignIn /
useCapxulVerifyOtp: after it
succeeds, useCapxulSession reads
null again.
Import
import { useCapxulSignOut } from "@capxul/sdk-react";Usage
"use client";
import { useCapxulSession, useCapxulSignOut } from "@capxul/sdk-react";
function SignOutButton() {
const session = useCapxulSession();
const signOut = useCapxulSignOut();
if (!session.data) return null;
return (
<button type="button" onClick={() => signOut.mutate()} disabled={signOut.isPending}>
{signOut.isPending ? "Signing out…" : "Sign out"}
</button>
);
}Parameters
None — the hook takes no parameters, and the mutation takes no input. Call
mutate() / mutateAsync() with no arguments.
Return type
import { type UseCapxulSignOutReturn } from "@capxul/sdk-react";
// UseMutationResult<void, CapxulError, void>There is no data payload — success simply means the session ended.
The hook returns TanStack Query's UseMutationResult. The most-used fields:
| Field | Description |
|---|---|
mutate | Fire the mutation (fire-and-forget; pair with onSuccess/onError callbacks). |
mutateAsync | Fire the mutation and get a Promise of the result. Rejects with a CapxulError on failure. |
data | The mutation result (typed per hook, shown above). undefined until the first success. |
error | A CapxulError when the last attempt failed, otherwise null. |
isPending | true while the mutation is in flight. Use it to disable submit buttons. |
reset | Clear the mutation state (data, error) back to idle. |
Mutations do not retry by default. The full field list is in the
TanStack Query useMutation reference;
see also the TanStack Query integration guide.
Cache behavior
Sign-out is the hard side of the auth boundary. When the mutation starts it cancels any in-flight balance fetch, and on success it resets (drops immediately, rather than refetching in the background) the auth-boundary queries:
["capxul", "session"](useCapxulSession)["capxul", "profile"](useCapxulProfile)["capxul", "accountLifecycle"](useCapxulAccountLifecycle)["capxul", "accountBalance"](useCapxulAccountBalance)
The reset means cached authenticated rows never linger on screen after
sign-out. Queries outside this boundary (org lists, activity, the current-user
context) are not reset automatically — unmount them when the session goes
null.
Errors
Failures surface as a CapxulError on error /
thrown from mutateAsync. The React Query cache reset above only runs when the
mutation succeeds.
Client method
This hook wraps client.auth.signOut() on the core SDK.