> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# `useSignOut`

Signs out users and clears authentication state. It logs the user out through the client and then refreshes the provider's user state, so [`useUser`](https://www.openfort.io/docs/products/embedded-wallet/react-native/hooks/useUser) and [`AuthBoundary`](https://www.openfort.io/docs/products/embedded-wallet/react-native/components/auth-boundary) fall back to their unauthenticated branch without a manual reload.

## Usage

```tsx
import { useSignOut } from '@openfort/react-native';
import { ActivityIndicator, Button, Text, View } from 'react-native';

function SignOutRow() {
  const { signOut, isLoading, isError, error } = useSignOut({
    onSuccess: () => console.log('Successfully signed out'),
    onError: (error) => console.error('Sign out failed:', error?.message),
  });

  return (
    <View>
      <Button title="Sign out" onPress={() => void signOut()} disabled={isLoading} />
      {isLoading && <ActivityIndicator />}
      {isError && <Text>{error?.message}</Text>}
    </View>
  );
}
```

## Hook options

Pass these options when initializing the hook:

```ts
type SignOutHookOptions = {
  onSuccess?: (data: {}) => void
  onError?: (error: OpenfortError) => void
  throwOnError?: boolean
}
```

## Return type

The hook returns the following:

```ts
type SignOutReturn = {
  signOut(options?: SignOutHookOptions): Promise<{} | { error: OpenfortError } | undefined>
  isLoading: boolean
  isError: boolean
  isSuccess: boolean
  error: OpenfortError | null | undefined
}
```

| Property | Type | Description |
|----------|------|-------------|
| `signOut` | `(options?) => Promise<...>` | Ends the session. Accepts the same options as the hook, applied to this call only. |
| `isLoading` | `boolean` | `true` while the sign out is in flight. |
| `isError` | `boolean` | `true` when the last attempt failed. |
| `isSuccess` | `boolean` | `true` after a completed sign out. |
| `error` | `OpenfortError \| null \| undefined` | The failure. `undefined` until an attempt fails. |

## Handling the result

`signOut` does not throw by default: a failure returns `{ error }` and sets `isError`. Errors that are not already an `OpenfortError` are wrapped in an `AuthenticationError` with the code `sign_out_error`. Set `throwOnError` — at the hook level, the call level, or both — to rethrow instead:

```tsx
try {
  await signOut({ throwOnError: true });
} catch (error) {
  // error is an OpenfortError
}
```

Callbacks passed to `useSignOut()` and to `signOut()` both run, hook-level first, so avoid duplicating navigation in the two places.

## Gotchas

* With no user signed in, `signOut()` returns immediately with `undefined`. The status stays `idle` and no callback fires, so do not rely on `onSuccess` to navigate away from a screen that may already be signed out.
* The hook clears the Openfort session, not your own backend session or any third-party auth session. Sign the user out of those separately.

## Related

* [`useUser`](https://www.openfort.io/docs/products/embedded-wallet/react-native/hooks/useUser) — Reflects the cleared session after sign out
* [`useGuestAuth`](https://www.openfort.io/docs/products/embedded-wallet/react-native/hooks/useGuestAuth) — Start a new guest session afterwards
* [`useOpenfortClient`](https://www.openfort.io/docs/products/embedded-wallet/react-native/hooks/useOpenfortClient) — Why `client.auth.logout()` alone leaves React state stale
