API Reference

Exceptions

Complete reference for the AuthException hierarchy.

AuthException

Base class for every Authyra error.

class AuthException implements Exception {
  final String message;
  final String? code;
  final dynamic originalError;
  final StackTrace? stackTrace;
}

Catch this to handle any Authyra failure generically, or catch a specific subclass for targeted handling.

try {
  await Authyra.instance.signIn('email', params: CredentialsSignInParams(
    email: email, password: password,
  ));
} on AuthenticationFailedException {
  setState(() => _error = 'Invalid email or password.');
} on AuthException catch (e) {
  setState(() => _error = e.message);
}

Configuration

ExceptionThrown when
NotInitializedExceptionAuthyra.instance (or AuthyraClient methods) is accessed before initialize() completes.
InvalidConfigurationExceptionConfiguration is invalid, e.g. missing storage in AuthyraClientBuilder.

Provider

ExceptionThrown when
ProviderNotFoundExceptionsignIn(providerId, ...) names an id not registered with the client.
ProviderAlreadyRegisteredExceptionTwo providers share the same id, at construction or via registerProvider.
InvalidProviderConfigExceptionregisterProvider is called with an empty id.

Authentication

ExceptionThrown when
AuthenticationCancelledExceptionThe user cancels an interactive flow (closes the OAuth browser tab).
AuthenticationFailedExceptionThe provider returned null (wrong credentials), an AuthCallbacks hook denied the operation, or an infrastructure error occurred. Carries an optional providerName.
InvalidCredentialsExceptionCredentials fail format validation before reaching the provider.
MissingAuthParametersExceptionRequired sign-in params are missing.

Session & Token

ExceptionThrown when
TokenExpiredExceptionThe active session's access token has expired and no refresh occurred (or autoRefresh: false).
RefreshDeniedExceptionA RefreshProvider signals a refresh that must not be retried: unsupported provider, no refresh token, or an AuthCallbacks.onBeforeTokenRefresh denial. TokenRefresher expires the session immediately instead of retrying.
TokenRefreshFailedExceptionA refresh attempt failed for a transient reason (network, server 5xx).
InvalidTokenExceptionA token is malformed or fails validation.
SessionNotFoundExceptionAn operation requiring an active session finds none (e.g. refreshSession() with nobody signed in).
SessionOperationExceptionA session mutation (save, update, switch, remove) fails. Wraps the original error.

Storage

ExceptionThrown when
StorageExceptionThe AuthStorage backend throws during initialize(), a read, or a write. Wraps the original error.

Network

ExceptionThrown when
NetworkExceptionA generic network failure occurs during a provider call.
AuthTimeoutExceptionAn OAuth flow exceeds OAuth2Config.timeout (default 5 minutes).
NoInternetExceptionNo network connectivity is detected (surfaced from a SocketException).

Validation

ExceptionThrown when
ValidationExceptionBase class for field-level validation failures.
InvalidEmailExceptionAn email fails format validation.
InvalidPasswordExceptionA password fails policy validation.

Multi-account

ExceptionThrown when
AccountNotFoundExceptionaccounts.switchTo(userId) or an internal registry lookup names an id with no registered session.
DuplicateAccountExceptionAn operation would register an account that already exists.

Platform

ExceptionThrown when
AuthPlatformExceptionA platform channel call fails (wraps a native PlatformException).
UnsupportedPlatformExceptionA feature is invoked on a platform that doesn't support it.

AuthyraErrorHandler

Internal helper that normalises unexpected errors into the most specific AuthException subclass available (SocketException → NoInternetException, TimeoutException → AuthTimeoutException, PlatformException → AuthPlatformException, otherwise a generic AuthException). Already-typed AuthExceptions pass through unchanged. You won't call this directly; it's what wraps errors thrown from signIn/signOut/refreshSession.

Copyright © 2026