BetterAuthClient class

The main Better Auth client class for Flutter applications.

This client provides a type-safe interface to interact with a Better Auth backend, supporting authentication, session management, and OAuth flows.

Basic Usage

final authClient = BetterAuthClient(
  baseUrl: String.fromEnvironment('BETTER_AUTH_URL'),
);

final result = await authClient.signIn.email(
  email: 'user@example.com',
  password: 'password123',
);

Reactive Session Management

The client provides a ValueNotifier for reactive session updates:

ValueListenableBuilder<Session?>(
  valueListenable: authClient.sessionNotifier,
  builder: (context, session, child) {
    if (session == null) return LoginPage();
    return HomePage(session: session);
  },
);

See also:

Constructors

BetterAuthClient({required String baseUrl, StorageInterface? storage, ClientOptions? options})
Creates a new BetterAuthClient instance.
BetterAuthClient.internal({required Dio dio, required String baseUrl, required StorageInterface storage})
Internal constructor for testing purposes.

Properties

account AccountModule
Module for account operations.
latefinal
baseUrl String
The base URL for API requests.
final
currentSession Session?
Gets the current session synchronously.
no setter
hashCode int
The hash code for this object.
no setterinherited
oauth OAuthModule
Module for OAuth operations.
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
session SessionModule
Module for session management.
latefinal
sessionNotifier ValueNotifier<Session?>
Provides a ValueNotifier for reactive session updates.
no setter
signIn SignInModule
Module for sign-in operations.
latefinal
signUp SignUpModule
Module for sign-up operations.
latefinal

Methods

dispose() → void
Disposes of resources used by the client.
getSession() Future<AuthResponse<Session>>
Fetches the current session from the server.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
signOut({Map<String, String>? fetchOptions}) Future<AuthResponse<void>>
Signs out the current user.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited