> ## 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.

# CrossmintAuthClient

> Flutter Abstract Interface Class

**Abstract Interface Class**

Authentication sub-client — email OTP, OAuth, wallet sign-in, and session lifecycle. Exposed on `CrossmintClient.auth`.

```dart theme={null}
abstract interface class CrossmintAuthClient
```

Observable via `state` (immediate), `stateListenable` (Flutter
`ValueListenable`), or `states` (`Stream`). Call `restoreSession` on
app startup (once `CrossmintClient.initialize` has completed) so any
persisted JWT can hydrate before the first frame.

## Properties

### state

```dart theme={null}
CrossmintAuthState get state
```

The current auth state snapshot.

### stateListenable

```dart theme={null}
ValueListenable<CrossmintAuthState> get stateListenable
```

Reactive handle on `state` — suitable for `ValueListenableBuilder`.

### states

```dart theme={null}
Stream<CrossmintAuthState> get states
```

Stream of auth-state changes. Emits on every state mutation.

## Methods

### restoreSession

```dart theme={null}
Future<void> restoreSession()
```

Reads any persisted session from `CrossmintAuthStorage` and applies it to the client. Safe to call once per app launch — prefer using the result of `CrossmintClient.initialize` which calls this internally.

### loginWithOAuth

```dart theme={null}
Future<void> loginWithOAuth(CrossmintOAuthProvider provider)
```

Opens the Crossmint-hosted OAuth flow for `provider` (Google, Twitter, etc.). The response comes back through `CrossmintAuthCallbackRouter` — make sure it is started before calling this.

### sendEmailOtp

```dart theme={null}
Future<CrossmintEmailOtpChallenge> sendEmailOtp(String email)
```

Requests the Crossmint API to send an email OTP to `email`. Returns a challenge that `confirmEmailOtp` completes.

### confirmEmailOtp

```dart theme={null}
Future<bool> confirmEmailOtp({
  required String email,
  required String emailId,
  required String token,
})
```

Submits an email OTP challenge — pass the `emailId` from the challenge and the `token` the user entered. Returns `true` on success.

### completeOAuth

```dart theme={null}
Future<bool> completeOAuth(Uri callbackUri)
```

Completes an OAuth flow from a deep-link callback URI. Normally invoked by `CrossmintAuthCallbackRouter`; call directly only for custom routing.

### completeOAuthWithOneTimeSecret

```dart theme={null}
Future<bool> completeOAuthWithOneTimeSecret(String oneTimeSecret)
```

Completes an OAuth flow from a one-time secret (SSR / server-mediated callbacks). Returns `true` on success.

### signInWithWallet

```dart theme={null}
Future<CrossmintWalletAuthChallenge> signInWithWallet(
  String address,
  String type,
)
```

Starts wallet-based authentication. Returns a challenge that the wallet must sign. `type` is `'evm'` or `'solana'`.

### authenticateWallet

```dart theme={null}
Future<bool> authenticateWallet(
  String address,
  String type,
  String signature,
)
```

Completes wallet-based authentication with the signed challenge.

### getSession

```dart theme={null}
Future<CrossmintAuthSession?> getSession()
```

Returns the current session (JWT + metadata), or `null` if not signed in. Does not hit the network — reads from in-memory state.

### getUser

```dart theme={null}
Future<CrossmintAuthenticatedUser?> getUser({bool forceRefresh = false})
```

Returns the authenticated user's profile. Caches the result; pass `forceRefresh: true` to bypass the cache and refetch.

### logout

```dart theme={null}
Future<void> logout()
```

Signs the user out — clears persisted storage, cached session/user, and POSTs to the Crossmint (or custom) logout endpoint.

### setJwt

```dart theme={null}
Future<void> setJwt(String? jwt)
```

Sets a custom JWT for "Bring Your Own Auth" (BYOA) flows.
