Account class
The Account service allows you to authenticate and manage a user account.
Properties
Methods
-
create(
{required String userId, required String email, required String password, String? name}) → Future< User> - Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the /account/verfication route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new account session.
-
createAnonymousSession(
) → Future< Session> - Use this endpoint to allow a new user to register an anonymous account in your project. This route will also create a new session for the user. To allow the new user to convert an anonymous account to a normal account, you need to update its email and password or create an OAuth2 session.
-
createDevice(
) → Future< Device> - Create an account switching device. A device is a container, scoped to one browser or app install, that holds multiple sessions and tracks which one is active. Once a device exists, session creation endpoints attach the new session to it automatically, so a single browser can stay signed in to several accounts and switch between them. A device holds at most one session per user: signing in again as a user it already holds replaces that user's session. The device lives as long as its newest session.
-
createEmailPasswordSession(
{required String email, required String password, int? duration}) → Future< Session> -
Allow the user to login into their account by providing a valid email and
password combination. This route will create a new session for the user.
Use the optional
durationparameter to create a shorter session, for example when the user doesn't choose "remember me". It must be at least 60 seconds and cannot exceed the project maximum session length. -
createEmailToken(
{required String userId, required String email, bool? phrase}) → Future< Token> -
Sends the user an email with a secret key for creating a session. If the
email address has never been used, a new account is created using the
provided
userId. Otherwise, if the email address is already attached to an account, the user ID is ignored. Then, the user will receive an email with the one-time password. Use the returned user ID and secret and submit a request to the POST /v1/account/sessions/token endpoint to complete the login process. The secret sent to the user's email is valid for 15 minutes. -
createEmailVerification(
{required String url}) → Future< Token> - Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the userId and secret arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the userId and secret parameters. Learn more about how to complete the verification process. The verification link sent to the user's email address is valid for 7 days.
-
createEmailVerificationOTP(
{bool? phrase}) → Future< Token> - Use this endpoint to send a 6-digit verification code to the currently logged in user's email address. Unlike createEmailVerification, this method requires no redirect URL, which makes it suitable for mobile and desktop apps that cannot host a verification page. Learn more about how to complete the verification process. The code sent to the user's email address is valid for 15 minutes.
-
createIdTokenSession(
{required IdTokenProvider provider, required String idToken, String? nonce, String? accessToken, int? accessTokenExpiry, String? name}) → Future< Session> - Allow the user to login to their account using an OpenID Connect ID token obtained natively from the OAuth2 provider, for example via Google Credential Manager on Android or Sign in with Apple on iOS. No browser or redirect is involved: the ID token is verified against the provider's published signing keys and a session is created in a single request.
-
createJWT(
{int? duration}) → Future< Jwt> - Use this endpoint to create a JSON Web Token. You can use the resulting JWT to authenticate on behalf of the current user when working with the Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes from its creation and will be invalid if the user will logout in that time frame.
-
createLDAPSession(
{required String username, required String password, int? duration}) → Future< Session> - Allow the user to login into their account by providing the username and password they use in the project's LDAP directory. The directory verifies the password; on the first sign-in an account is created from the directory entry, and on later sign-ins the name, email and phone follow the directory. This endpoint requires LDAP to be configured and enabled for the project. A user is limited to 10 active sessions at a time by default. Learn more about session limits.
-
createMagicURLToken(
{required String userId, required String email, String? url, bool? phrase}) → Future< Token> - Sends the user an email with a secret key for creating a session. If the provided user ID has not been registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the POST /v1/account/sessions/token endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour.
-
createMFAAuthenticator(
{required AuthenticatorType type}) → Future< MfaType> - Add an authenticator app to be used as an MFA factor. Verify the authenticator using the verify authenticator method.
-
createMfaAuthenticator(
{required AuthenticatorType type}) → Future< MfaType> - Add an authenticator app to be used as an MFA factor. Verify the authenticator using the verify authenticator method.
-
createMFAChallenge(
{required AuthenticationFactor factor}) → Future< MfaChallenge> - Begin the process of MFA verification after sign-in. Finish the flow with updateMfaChallenge method.
-
createMfaChallenge(
{required AuthenticationFactor factor}) → Future< MfaChallenge> - Begin the process of MFA verification after sign-in. Finish the flow with updateMfaChallenge method.
-
createMFARecoveryCodes(
) → Future< MfaRecoveryCodes> - Generate recovery codes as backup for MFA flow. It's recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in createMfaChallenge method.
-
createMfaRecoveryCodes(
) → Future< MfaRecoveryCodes> - Generate recovery codes as backup for MFA flow. It's recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in createMfaChallenge method.
-
createOAuth2Session(
{required OAuthProvider provider, String? success, String? failure, List< String> ? scopes, String? state}) → Future - Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed.
-
createOAuth2Token(
{required OAuthProvider provider, String? success, String? failure, List< String> ? scopes, String? state}) → Future - Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed.
-
createPasskey(
{String? passkeyId, String? name}) → Future< PasskeyChallenge> -
Start registering a passkey for the currently logged in user. The session
must have signed in or completed an MFA challenge within the last 10
minutes. Pass the returned
publicKeyoptions tonavigator.credentials.create(), then complete the registration with Update passkey verification. The passkey stays pending until verified, and the challenge expires after 5 minutes. -
createPasskeyToken(
) → Future< PasskeyChallenge> -
Start signing in with a passkey. No email or user ID is needed: pass the
returned
publicKeyoptions tonavigator.credentials.get()and the user picks one of their passkeys. Then call Update passkey token with the credential to receive a token, and exchange it with Create session. The challenge expires after 5 minutes. -
createPhoneToken(
{required String userId, required String phone}) → Future< Token> - Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the POST /v1/account/sessions/token endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.
-
createPhoneVerification(
) → Future< Token> - Use this endpoint to send a verification SMS to the currently logged in user. This endpoint is meant for use after updating a user's phone number using the accountUpdatePhone endpoint. Learn more about how to complete the verification process. The verification code sent to the user's phone number is valid for 15 minutes.
-
createPushTarget(
{required String targetId, required String identifier, String? providerId, String? bundleId, String? environment}) → Future< Target> - Use this endpoint to register a device for push notifications. Provide a target ID (custom or generated using ID.unique()), a device identifier (usually a device token), and optionally specify which provider should send notifications to this target. The target is automatically linked to the current session and includes device information like brand and model. A session holds one push target per provider, so if one already exists this endpoint updates and returns that target instead of creating a second one, and a device that rotates its token is never notified twice.
-
createRecovery(
{required String email, required String url}) → Future< Token> - Sends the user an email with a temporary secret key for password reset. When the user clicks the confirmation link he is redirected back to your app password reset URL with the secret key and email address values attached to the URL query string. Use the query string params to submit a request to the PUT /account/recovery endpoint to complete the process. The verification link sent to the user's email address is valid for 1 hour.
-
createRecoveryOTP(
{required String email, bool? phrase}) → Future< Token> - Use this endpoint to send a 6-digit password recovery code to the user's email address. Unlike createRecovery, this method requires no redirect URL, which makes it suitable for mobile and desktop apps that cannot host a recovery page. Learn more about how to complete the recovery process. The code sent to the user's email address is valid for 15 minutes.
-
createSession(
{required String userId, required String secret}) → Future< Session> - Use this endpoint to create a session from token. Provide the userId and secret parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.
-
createVerification(
{required String url}) → Future< Token> - Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the userId and secret arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the userId and secret parameters. Learn more about how to complete the verification process. The verification link sent to the user's email address is valid for 7 days.
-
deleteConsent(
{required String consentId}) → Future - Delete an OAuth2 consent by its unique ID. All token families issued under the consent are revoked, and the app must ask for consent again to regain access.
-
deleteConsentToken(
{required String consentId, required String tokenId}) → Future - Delete a token family issued under an OAuth2 consent by its unique ID. The access and refresh tokens of the family stop working immediately; other token families and the consent itself are unaffected.
-
deleteDevice(
{required String deviceId}) → Future - Delete the account switching device for the current browser. Every session the device holds is signed out, each firing its own session delete event, the device is removed, and both the device and session cookies are cleared. Use the string 'current' to reference the current browser's device.
-
deleteIdentity(
{required String identityId}) → Future - Delete an identity by its unique ID.
-
deleteMFAAuthenticator(
{required AuthenticatorType type}) → Future - Delete an authenticator for a user by ID.
-
deleteMfaAuthenticator(
{required AuthenticatorType type}) → Future - Delete an authenticator for a user by ID.
-
deletePasskey(
{required String passkeyId}) → Future - Delete a passkey from the currently logged in user. The passkey can no longer be used to sign in, although it may remain stored on the user's device. The session must have signed in or completed an MFA challenge within the last 10 minutes.
-
deletePushTarget(
{required String targetId}) → Future - Delete a push notification target for the currently logged in user. After deletion, the device will no longer receive push notifications. The target must exist and belong to the current user.
-
deleteSession(
{required String sessionId}) → Future - Logout the user. Use 'current' as the session ID to logout on this device, use a session ID to logout on another device. If you're looking to logout the user on all devices, use Delete Sessions instead.
-
deleteSessions(
{bool? current}) → Future -
Delete all sessions from the user account and remove any sessions cookies
from the end client. Pass
currentas false to keep the session making the request and sign out of every other session. -
get(
) → Future< User> - Get the currently logged in user.
-
getConsent(
{required String consentId}) → Future< Oauth2Consent> - Get an OAuth2 consent the current user has given to a third-party app by its unique ID.
-
getConsentToken(
{required String consentId, required String tokenId}) → Future< Oauth2ConsentToken> - Get a token family issued under an OAuth2 consent by its unique ID. The token secrets themselves are never returned.
-
getDevice(
{required String deviceId}) → Future< Device> - Get the account switching device for the current browser, including every session it holds, the name of the user each session belongs to, and the ID of the active session. Use the string 'current' to reference the current browser's device.
-
getMFARecoveryCodes(
) → Future< MfaRecoveryCodes> - Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using createMfaRecoveryCodes method. An OTP challenge is required to read recovery codes.
-
getMfaRecoveryCodes(
) → Future< MfaRecoveryCodes> - Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using createMfaRecoveryCodes method. An OTP challenge is required to read recovery codes.
-
getPasskey(
{required String passkeyId}) → Future< Passkey> - Get a verified passkey of the currently logged in user by its unique ID.
-
getPrefs(
) → Future< Preferences> - Get the preferences as a key-value object for the currently logged in user.
-
getSession(
{required String sessionId}) → Future< Session> - Use this endpoint to get a logged in user's session using a Session ID. Inputting 'current' will return the current session being used.
-
listConsents(
{List< String> ? queries, bool? total}) → Future<Oauth2ConsentList> - Get a list of the OAuth2 consents the current user has given to third-party apps.
-
listConsentTokens(
{required String consentId, List< String> ? queries, bool? total}) → Future<Oauth2ConsentTokenList> - Get a list of the token families issued under an OAuth2 consent. Each entry represents one authorized device or session; the token secrets themselves are never returned.
-
listIdentities(
{List< String> ? queries, bool? total}) → Future<IdentityList> - Get the list of identities for the currently logged in user.
-
listMemberships(
{List< String> ? queries, bool? total}) → Future<MembershipList> - Get the team memberships of the currently logged in user.
-
listMFAFactors(
) → Future< MfaFactors> - List the factors available on the account to be used as a MFA challange.
-
listMfaFactors(
) → Future< MfaFactors> - List the factors available on the account to be used as a MFA challange.
-
listPasskeys(
{List< String> ? queries, bool? total}) → Future<PasskeyList> - Get the list of verified passkeys registered by the currently logged in user.
-
listSessions(
{bool? total}) → Future< SessionList> - Get the list of active sessions across different devices for the currently logged in user.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
updateDeviceSession(
{required String deviceId, required String sessionId}) → Future< Session> - Switch the active account on an account switching device to one of the sessions it holds. The chosen session becomes active and its secret is written to the browser's session cookie, so subsequent requests authenticate as that account. Use the string 'current' to reference the current browser's device.
-
updateEmail(
{required String email, required String password}) → Future< User> - Update currently logged in user account email address. After changing user address, the user confirmation status will get reset. A new confirmation email is not sent automatically however you can use the send confirmation email endpoint again to send the confirmation email. For security measures, user password is required to complete this request. This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password.
-
updateEmailVerification(
{required String userId, required String secret}) → Future< Token> - Use this endpoint to complete the user email verification process. Use both the userId and secret parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
-
updateEmailVerificationOTP(
{required String userId, required String secret}) → Future< Token> - Use this endpoint to complete the user email verification process using the 6-digit code that was emailed by createEmailVerificationOTP. Pass the userId of the user being verified along with the secret code from the email. If confirmed, this route will return a 200 status code and the code is consumed.
-
updateMagicURLSession(
{required String userId, required String secret}) → Future< Session> - Use this endpoint to create a session from token. Provide the userId and secret parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.
-
updateMFA(
{required bool mfa}) → Future< User> - Enable or disable MFA on an account.
-
updateMFAAuthenticator(
{required AuthenticatorType type, required String otp}) → Future< User> - Verify an authenticator app after adding it using the add authenticator method.
-
updateMfaAuthenticator(
{required AuthenticatorType type, required String otp}) → Future< User> - Verify an authenticator app after adding it using the add authenticator method.
-
updateMFAChallenge(
{required String challengeId, required String otp}) → Future< Session> - Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use createMfaChallenge method.
-
updateMfaChallenge(
{required String challengeId, required String otp}) → Future< Session> - Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use createMfaChallenge method.
-
updateMFARecoveryCodes(
) → Future< MfaRecoveryCodes> - Regenerate recovery codes that can be used as backup for MFA flow. Before regenerating codes, they must be first generated using createMfaRecoveryCodes method. An OTP challenge is required to regenreate recovery codes.
-
updateMfaRecoveryCodes(
) → Future< MfaRecoveryCodes> - Regenerate recovery codes that can be used as backup for MFA flow. Before regenerating codes, they must be first generated using createMfaRecoveryCodes method. An OTP challenge is required to regenreate recovery codes.
-
updateName(
{required String name}) → Future< User> - Update currently logged in user account name.
-
updatePasskey(
{required String passkeyId, required String name}) → Future< Passkey> - Rename a passkey of the currently logged in user.
-
updatePasskeyToken(
{required String challengeId, required Map credential}) → Future< TokenSecret> -
Complete a passkey sign-in started with Create passkey
token. Pass
the challenge ID and the JSON form of the credential returned by
navigator.credentials.get(), for examplecredential.toJSON(). The returned token includes its secret and expires after 1 minute: exchange it for a session with Create session. Passkeys require user verification, so the session also satisfies MFA. Each challenge can only be used once. -
updatePasskeyVerification(
{required String passkeyId, required Map credential}) → Future< Passkey> -
Complete a passkey registration started with Create
passkey. Pass the
JSON form of the credential returned by
navigator.credentials.create(), for examplecredential.toJSON(). Each registration can be verified once; a failed attempt requires starting it again. -
updatePassword(
{required String password, String? oldPassword}) → Future< User> - Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional.
-
updatePhone(
{required String phone, required String password}) → Future< User> - Update the currently logged in user's phone number. After updating the phone number, the phone verification status will be reset. A confirmation SMS is not sent automatically, however you can use the POST /account/verification/phone endpoint to send a confirmation SMS.
-
updatePhoneSession(
{required String userId, required String secret}) → Future< Session> - Use this endpoint to create a session from token. Provide the userId and secret parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.
-
updatePhoneVerification(
{required String userId, required String secret}) → Future< Token> - Use this endpoint to complete the user phone verification process. Use the userId and secret that were sent to your user's phone number to verify the user email ownership. If confirmed this route will return a 200 status code.
-
updatePrefs(
{required Map prefs}) → Future< User> - Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded.
-
updatePushTarget(
{required String targetId, required String identifier, String? bundleId, String? environment}) → Future< Target> - Update the currently logged in user's push notification target. You can modify the target's identifier (device token) and provider ID (token, email, phone etc.). The target must exist and belong to the current user. If you change the provider ID, notifications will be sent through the new messaging provider instead.
-
updateRecovery(
{required String userId, required String secret, required String password}) → Future< Token> - Use this endpoint to complete the user account password reset. Both the userId and secret arguments will be passed as query parameters to the redirect URL you have provided when sending your request to the POST /account/recovery endpoint.
-
updateRecoveryOTP(
{required String userId, required String secret, required String password}) → Future< Token> - Use this endpoint to complete the user password recovery process using the 6-digit code that was emailed by createRecoveryOTP. Pass the userId of the user along with the secret code from the email and the new password to set. If confirmed, this route will return a 200 status code, the code is consumed and the user's password is updated.
-
updateSession(
{required String sessionId}) → Future< Session> - Use this endpoint to extend a session's length. Extending a session is useful when session expiry is short. If the session was created using an OAuth provider, this endpoint refreshes the access token from the provider.
-
updateStatus(
) → Future< User> - Block the currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. To completely delete a user, use the Users API instead.
-
updateVerification(
{required String userId, required String secret}) → Future< Token> - Use this endpoint to complete the user email verification process. Use both the userId and secret parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited