Capxul Docs
HooksAuth & session

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:

FieldDescription
mutateFire the mutation (fire-and-forget; pair with onSuccess/onError callbacks).
mutateAsyncFire the mutation and get a Promise of the result. Rejects with a CapxulError on failure.
dataThe mutation result (typed per hook, shown above). undefined until the first success.
errorA CapxulError when the last attempt failed, otherwise null.
isPendingtrue while the mutation is in flight. Use it to disable submit buttons.
resetClear 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:

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.

On this page