GoTrueClient class
API client to interact with gotrue server.
url URL of gotrue instance
autoRefreshToken whether to refresh the token automatically or not. Defaults to true.
httpClient custom http client.
asyncStorage local storage to store pkce code verifiers. Required when using the pkce flow.
Set flowType to AuthFlowType.implicit to perform old implicit auth flow.
Constructors
-
GoTrueClient({String? url, Map<
String, String> ? headers, bool? autoRefreshToken, Client? httpClient, GotrueAsyncStorage? asyncStorage, AuthFlowType flowType = AuthFlowType.pkce}) - API client to interact with gotrue server.
Properties
- admin ↔ GoTrueAdminApi
-
Namespace for the GoTrue API methods.
These can be used for example to get a user from a JWT in a server environment or reset a user's password.
latefinal
- currentSession → Session?
-
Returns the current session, if any;
no setter
- currentUser → User?
-
Returns the current logged in user, asociated to currentSession if any;
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
headers
→ Map<
String, String> -
Getter for the headers
no setter
- mfa ↔ GoTrueMFAApi
-
Namespace for the GoTrue MFA API methods.
latefinal
-
onAuthStateChange
→ Stream<
AuthState> -
Receive a notification every time an auth event happens.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void -
exchangeCodeForSession(
String authCode) → Future< AuthSessionUrlResponse> - Verifies the PKCE code verifyer and retrieves a session.
-
getClaims(
[String? jwt, GetClaimsOptions? options]) → Future< GetClaimsResponse> -
Extracts the JWT claims present in the access token by first verifying the
JWT against the server's JSON Web Key Set endpoint
/.well-known/jwks.jsonwhich is often cached, resulting in significantly faster responses. Prefer this method over getUser which always sends a request to the Auth server for each JWT. -
getLinkIdentityUrl(
OAuthProvider provider, {String? redirectTo, String? scopes, Map< String, String> ? queryParams}) → Future<OAuthResponse> - Returns the URL to link the user's identity with an OAuth provider.
-
getOAuthSignInUrl(
{required OAuthProvider provider, String? redirectTo, String? scopes, Map< String, String> ? queryParams}) → Future<OAuthResponse> - Generates a link to log in an user via a third-party provider.
-
getSessionFromUrl(
Uri originUrl, {bool storeSession = true}) → Future< AuthSessionUrlResponse> - Gets the session data from a magic link or oauth2 callback URL
-
getSSOSignInUrl(
{String? providerId, String? domain, String? redirectTo, String? captchaToken}) → Future< String> - Obtains a URL to perform a single-sign on using an enterprise Identity Provider. The redirect URL is implementation and SSO protocol specific.
-
getUser(
[String? jwt]) → Future< UserResponse> -
Gets the current user details from current session or custom
jwt -
getUserIdentities(
) → Future< List< UserIdentity> > - Gets all the identities linked to a user.
-
linkIdentityWithIdToken(
{required OAuthProvider provider, required String idToken, String? accessToken, String? nonce, String? captchaToken}) → Future< AuthResponse> - Link an identity to the current user using an ID token.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reauthenticate(
) → Future< void> - Sends a reauthentication OTP to the user's email or phone number.
-
recoverSession(
String jsonStr) → Future< AuthResponse> - Recover session from stringified Session.
-
refreshSession(
[String? refreshToken]) → Future< AuthResponse> -
Returns a new session, regardless of expiry status.
Takes in an optional
refreshToken. If not provided, then refreshSession() will attempt to retrieve it from the current session. If no refresh token is available (neither provided nor in current session), an error will be thrown. -
resend(
{String? email, String? phone, required OtpType type, String? emailRedirectTo, String? captchaToken}) → Future< ResendResponse> - Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
-
resetPasswordForEmail(
String email, {String? redirectTo, String? captchaToken}) → Future< void> - Sends a reset request to an email address.
-
setInitialSession(
String jsonStr) → Future< void> - Set the initial session to the session obtained from local storage
-
setSession(
String refreshToken) → Future< AuthResponse> - Sets the session data from refresh_token and returns the current session.
-
signInAnonymously(
{Map< String, dynamic> ? data, String? captchaToken}) → Future<AuthResponse> - Creates a new anonymous user.
-
signInWithIdToken(
{required OAuthProvider provider, required String idToken, String? accessToken, String? nonce, String? captchaToken}) → Future< AuthResponse> -
Allows signing in with an ID token issued by supported providers.
Common supported providers include Apple, Google, Facebook, Kakao, and Keycloak.
The
idTokenis verified for validity and a new session is established. -
signInWithOtp(
{String? email, String? phone, String? emailRedirectTo, bool? shouldCreateUser, Map< String, dynamic> ? data, String? captchaToken, OtpChannel channel = OtpChannel.sms}) → Future<void> - Log in a user using magiclink or a one-time password (OTP).
-
signInWithPassword(
{String? email, String? phone, required String password, String? captchaToken}) → Future< AuthResponse> - Log in an existing user with an email and password or phone and password.
-
signOut(
{SignOutScope scope = SignOutScope.local}) → Future< void> - Signs out the current user, if there is a logged in user.
-
signUp(
{String? email, String? phone, required String password, String? emailRedirectTo, Map< String, dynamic> ? data, String? captchaToken, OtpChannel channel = OtpChannel.sms}) → Future<AuthResponse> - Creates a new user.
-
startAutoRefresh(
) → void - Starts an auto-refresh process in the background. Close to the time of expiration a process is started to refresh the session. If refreshing fails it will be retried for as long as necessary.
-
stopAutoRefresh(
) → void - Stops an active auto refresh process running in the background (if any).
-
toString(
) → String -
A string representation of this object.
inherited
-
unlinkIdentity(
UserIdentity identity) → Future< void> - Unlinks an identity from a user by deleting it.
-
updateUser(
UserAttributes attributes, {String? emailRedirectTo}) → Future< UserResponse> - Updates user data, if there is a logged in user.
-
verifyOTP(
{String? email, String? phone, String? token, required OtpType type, String? redirectTo, String? captchaToken, String? tokenHash}) → Future< AuthResponse> - Log in a user given a User supplied OTP received via mobile.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited