NhostAuthClient class
The Nhost authentication service.
Supports user authentication, MFA, OTP, and various user management functions. implements
See https://docs.nhost.io/reference/sdk/authentication for more info.
Constructors
- NhostAuthClient({required String url, UserSession? session, AuthStore? authStore, Duration? tokenRefreshInterval, Client? httpClient})
-
authStore
(optional) is used to persist authentication tokens between restarts of your app. If not provided, the tokens will not be persisted.
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
- userSession → UserSession
-
no setter
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, String? ticket}) → 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, ornull
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 NhostAuthClient to begin identifying as the user described by
session
. -
signInAnonymous(
String? displayName, String? locale, Map< String, dynamic> ? metadata) → Future<void> - Authenticates a user anonymously.
-
signInEmailPassword(
{required String email, required String password}) → Future< AuthResponse> -
Authenticates a user using an
email
andpassword
. -
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(
{required String phoneNumber, String? locale, String? defaultRole, Map< String, Object?> ? metadata, List<String> ? roles, String? displayName, String? redirectTo}) → 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
andpassword
. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited