AuthClient class

The Nhost authentication service.

Supports user authentication, MFA, OTP, and various user management functions.

See https://docs.nhost.io/reference/sdk/authentication for more info.

Constructors

AuthClient({required String baseUrl, required UserSession session, required AuthStore authStore, Duration? tokenRefreshInterval, required Client httpClient})
backendUrl is the Nhost "Backend URL" that can be found on your Nhost project page.

Properties

accessToken String?
The currently logged-in user's Json Web Token, or null if unauthenticated.
no setter
authenticationState AuthenticationState
Whether a user is logged in, not logged in, or if a sign-in is in process.
no setter
currentUser User?
Currently logged-in user, or null if unauthenticated.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addAuthStateChangedCallback(AuthStateChangedCallback callback) UnsubscribeDelegate
Add a callback that will be invoked when the service's authentication state changes.
addSessionRefreshFailedCallback(SessionRefreshFailedCallback callback) UnsubscribeDelegate
Add a callback that will be invoked when the service fails to refresh its session.
addTokenChangedCallback(TokenChangedCallback callback) UnsubscribeDelegate
Add a callback that will be invoked when the service's token changes.
changeEmail(String newEmail) Future<void>
Changes the email address of a logged in user.
changePassword({required String newPassword}) Future<void>
Changes the password of the logged in user.
clearSession() Future<void>
Clears the active session, if any, and removes all derived state.
close() → void
Releases the service's resources.
completeMfaSignIn({required String otp, required String ticket}) Future<AuthResponse>
Complete an MFA sign in using a time-based one-time password.
completeOAuthProviderSignIn(Uri redirectUrl) Future<void>
Completes an OAuth provider sign in, given the Nhost OAuth provider's redirectUrl.
completeSmsPasswordlessSignIn(String phoneNumber, String otp) Future<AuthResponse>
disableMfa(String code) Future<void>
Disable MFA (Multi-Factor Authentication).
enableMfa(String totp) Future<void>
Enable MFA (Multi-Factor Authentication).
generateMfa() Future<MultiFactorAuthResponse>
Generates an MFA (Multi-Factor Authentication) QR-code.
getClaim(String jwtClaim) String?
Gets the value of a JWT claim named jwtClaim associated with the current authentication session, or null if not found/unauthenticated.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resetPassword({required String email, String? redirectTo}) Future<void>
Resets a user's password.
sendVerificationEmail({required String email, String? redirectTo}) Future<void>
Resends the sign-up verification email to the user with the specified email.
setSession(Session session) Future<void>
Updates the AuthClient to begin identifying as the user described by session.
signInEmailPassword({required String email, required String password}) Future<AuthResponse>
Authenticates a user using an email and password.
signInWithEmailPasswordless(String email, {String? redirectTo}) Future<void>
Signs in a user with a magic link.
signInWithRefreshToken(String refreshToken) Future<AuthResponse>
Attempts a sign in using a refreshToken from a previously sign in.
signInWithSmsPasswordless(String phoneNumber) Future<void>
Authenticates a user using a phoneNumber.
signInWithStoredCredentials() Future<AuthResponse>
Attempts a sign in using the credentials stored in the AuthStore provided during construction.
signOut({bool all = false}) Future<AuthResponse>
Logs out the current user.
signUp({required String email, required String password, String? locale, String? defaultRole, Map<String, Object?>? metadata, List<String>? roles, String? displayName, String? redirectTo}) Future<AuthResponse>
Creates a user from an email and password.
toString() String
A string representation of this object.
inherited

Operators

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