> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crossmint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Hooks

> React hooks for React SDK reference for Crossmint authentication

## useCrossmintAuth()

Access Crossmint authentication state and actions: `login`, `logout`, the current `user`, `jwt`, and auth `status`. Must be used within a `CrossmintAuthProvider`.

### Returns

<ResponseField name="crossmintAuth" type="any">
  The underlying Crossmint auth client instance.
</ResponseField>

<ResponseField name="getUser" type="() => void">
  Fetch and refresh the current authenticated user.
</ResponseField>

<ResponseField name="jwt" type="string">
  Current JWT authentication token, if authenticated.
</ResponseField>

<ResponseField name="login" type="(defaultEmail: string | MouseEvent<Element, MouseEvent>) => void">
  Trigger the login flow. Optionally pass a default email.
</ResponseField>

<ResponseField name="loginMethods" type="LoginMethod[]">
  Configured login methods.
</ResponseField>

<ResponseField name="loginWithOAuth" type="(provider: OAuthProvider) => Promise<void>">
  Initiate a login flow with the specified OAuth provider (e.g. "google", "twitter").
</ResponseField>

<ResponseField name="logout" type="() => Promise<void>">
  Log the user out and clear the session.
</ResponseField>

<ResponseField name="status" type="AuthStatus">
  Authentication status: "logged-in" | "logged-out" | "in-progress" | "initializing".
</ResponseField>

<ResponseField name="user" type="SDKExternalUser">
  The currently authenticated user object.
</ResponseField>

### Usage

```tsx theme={null}
import { useCrossmintAuth } from "@crossmint/client-sdk-react-ui";

function LoginButton() {
    const { login, logout, user, status } = useCrossmintAuth();

    if (status === "logged-in") {
        return (
            <div>
                <p>Welcome, {user?.email}</p>
                <button onClick={logout}>Logout</button>
            </div>
        );
    }

    return <button onClick={() => login()}>Sign In</button>;
}
```
