Appwrite.Services.Accounts (appwrite v1.0.0)

View Source

The Account service allows you to authenticate and manage a user account.

You can use the account service to update user information, retrieve sessions across devices, and fetch security logs. Authentication is supported via email/password, magic URLs, OAuth2, phone OTP, and anonymous sessions.

Summary

Functions

Create an anonymous session.

Create a session using email and password.

Create an email token for passwordless / magic-link authentication.

Create a JWT for the current user.

Create a magic URL token for passwordless authentication.

Create a new MFA authenticator of the given type (e.g. "totp").

Create an MFA challenge for a given factor.

Generate new MFA recovery codes.

Build the OAuth2 authorization URL for the given provider.

Build the OAuth2 token URL (redirects user to provider, then creates a session token).

Create a phone token for SMS-based OTP authentication.

Send a phone verification SMS to the current user's registered phone number.

Register a push notification target (device token).

Send a password recovery email.

Create a session from a short-lived token (userId + secret).

Send an email verification link to the current user.

Delete an identity by its unique ID.

Delete an MFA authenticator.

Delete a push notification target.

Delete a session by ID. Use "current" to log out of the active session.

Delete all active sessions (log out from all devices).

Get the currently logged-in user.

Get the MFA recovery codes for the current account.

Get the current user's preferences object.

Get a session by ID. Use "current" for the active session.

List identities for the currently logged-in user.

List activity logs for the currently logged-in user.

List all available MFA factors on the current account.

List all active sessions for the current user.

Update the currently logged-in user's email address.

Complete a magic-URL session (supply userId + secret from the email link).

Enable or disable MFA on the current account.

Verify and activate an MFA authenticator by providing its one-time password.

Complete an MFA challenge by providing the one-time password.

Regenerate MFA recovery codes (requires a completed OTP challenge).

Update the current user's display name.

Update the current user's password. old_password is required unless the account has no password.

Update the current user's phone number. Requires current password.

Complete a phone OTP session (supply userId + secret from the SMS).

Confirm phone verification using the userId and secret from the verification SMS.

Replace the current user's preferences object.

Update a push notification target's device token.

Complete the password reset flow.

Extend or update an existing session.

Block the current account (sets status to false).

Confirm email verification using the userId and secret from the verification link.

Functions

create(user_id \\ nil, email, password, name \\ nil)

@spec create(String.t() | nil, String.t(), String.t(), String.t() | nil) ::
  {:ok, map()} | {:error, any()}

Create a new account.

Parameters

  • user_id — unique ID; auto-generated when nil
  • email (required)
  • password (required)
  • name (optional)

create_anonymous_session()

@spec create_anonymous_session() :: {:ok, map()} | {:error, any()}

Create an anonymous session.

create_email_password_session(email, password)

@spec create_email_password_session(String.t(), String.t()) ::
  {:ok, map()} | {:error, any()}

Create a session using email and password.

create_email_token(user_id, email, phrase \\ nil)

@spec create_email_token(String.t(), String.t(), boolean() | nil) ::
  {:ok, map()} | {:error, any()}

Create an email token for passwordless / magic-link authentication.

create_jwt(duration \\ nil)

@spec create_jwt(integer() | nil) :: {:ok, map()} | {:error, any()}

Create a JWT for the current user.

Parameters

  • duration (optional) — seconds before expiry; default 900, max 3600

create_magic_url_token(user_id, email, url \\ nil, phrase \\ nil)

@spec create_magic_url_token(
  String.t(),
  String.t(),
  String.t() | nil,
  boolean() | nil
) ::
  {:ok, map()} | {:error, any()}

Create a magic URL token for passwordless authentication.

create_mfa_authenticator(type)

@spec create_mfa_authenticator(String.t()) :: {:ok, map()} | {:error, any()}

Create a new MFA authenticator of the given type (e.g. "totp").

create_mfa_challenge(factor)

@spec create_mfa_challenge(String.t()) :: {:ok, map()} | {:error, any()}

Create an MFA challenge for a given factor.

factor must be a valid Appwrite.Consts.AuthenticationFactor value.

create_mfa_recovery_codes()

@spec create_mfa_recovery_codes() :: {:ok, map()} | {:error, any()}

Generate new MFA recovery codes.

create_oauth2_session(provider, success \\ nil, failure \\ nil, scopes \\ nil)

@spec create_oauth2_session(
  String.t(),
  String.t() | nil,
  String.t() | nil,
  [String.t()] | nil
) :: {:ok, String.t()} | {:error, any()}

Build the OAuth2 authorization URL for the given provider.

Returns the URL as a string — the caller should redirect the user to it.

create_oauth2_token(provider, success \\ nil, failure \\ nil, scopes \\ nil)

@spec create_oauth2_token(
  String.t(),
  String.t() | nil,
  String.t() | nil,
  [String.t()] | nil
) :: {:ok, String.t()} | {:error, any()}

Build the OAuth2 token URL (redirects user to provider, then creates a session token).

create_phone_token(user_id, phone)

@spec create_phone_token(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Create a phone token for SMS-based OTP authentication.

create_phone_verification()

@spec create_phone_verification() :: {:ok, map()} | {:error, any()}

Send a phone verification SMS to the current user's registered phone number.

create_push_target(target_id, identifier, provider_id \\ nil)

@spec create_push_target(String.t(), String.t(), String.t() | nil) ::
  {:ok, map()} | {:error, any()}

Register a push notification target (device token).

create_recovery(email, url)

@spec create_recovery(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Send a password recovery email.

Parameters

  • email (required) — the user's email address
  • url (required) — redirect URL embedded in the recovery email

create_session(user_id, secret)

@spec create_session(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Create a session from a short-lived token (userId + secret).

create_verification(url)

@spec create_verification(String.t()) :: {:ok, map()} | {:error, any()}

Send an email verification link to the current user.

delete_identity(identity_id)

@spec delete_identity(String.t()) :: {:ok, map()} | {:error, any()}

Delete an identity by its unique ID.

delete_mfa_authenticator(type)

@spec delete_mfa_authenticator(String.t()) :: {:ok, map()} | {:error, any()}

Delete an MFA authenticator.

delete_push_target(target_id)

@spec delete_push_target(String.t()) :: {:ok, map()} | {:error, any()}

Delete a push notification target.

delete_session(session_headers, session_id)

@spec delete_session(map(), String.t()) :: {:ok, map()} | {:error, any()}

Delete a session by ID. Use "current" to log out of the active session.

delete_sessions()

@spec delete_sessions() :: {:ok, map()} | {:error, any()}

Delete all active sessions (log out from all devices).

get()

@spec get() :: {:ok, map()} | {:error, any()}

Get the currently logged-in user.

get_mfa_recovery_codes()

@spec get_mfa_recovery_codes() :: {:ok, map()} | {:error, any()}

Get the MFA recovery codes for the current account.

get_prefs()

@spec get_prefs() :: {:ok, map()} | {:error, any()}

Get the current user's preferences object.

get_session(session_headers, session_id)

@spec get_session(map(), String.t()) :: {:ok, map()} | {:error, any()}

Get a session by ID. Use "current" for the active session.

list_identities(queries \\ nil, total \\ nil)

@spec list_identities([String.t()] | nil, boolean() | nil) ::
  {:ok, map()} | {:error, any()}

List identities for the currently logged-in user.

Parameters

  • queries (optional)
  • total (optional) — when false, skips total count calculation

list_logs(queries \\ nil, total \\ nil)

@spec list_logs([String.t()] | nil, boolean() | nil) :: {:ok, map()} | {:error, any()}

List activity logs for the currently logged-in user.

Parameters

  • queries (optional)
  • total (optional) — when false, skips total count calculation

list_mfa_factors()

@spec list_mfa_factors() :: {:ok, map()} | {:error, any()}

List all available MFA factors on the current account.

list_sessions()

@spec list_sessions() :: {:ok, map()} | {:error, any()}

List all active sessions for the current user.

update_email(email, password)

@spec update_email(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Update the currently logged-in user's email address.

Requires the current password for confirmation.

update_magic_url_session(user_id, secret)

@spec update_magic_url_session(String.t(), String.t()) ::
  {:ok, map()} | {:error, any()}

Complete a magic-URL session (supply userId + secret from the email link).

update_mfa(mfa)

@spec update_mfa(boolean()) :: {:ok, map()} | {:error, any()}

Enable or disable MFA on the current account.

update_mfa_authenticator(type, otp)

@spec update_mfa_authenticator(String.t(), String.t()) ::
  {:ok, map()} | {:error, any()}

Verify and activate an MFA authenticator by providing its one-time password.

update_mfa_challenge(challenge_id, otp)

@spec update_mfa_challenge(String.t(), String.t()) ::
  {:ok, Appwrite.Types.Session.t()} | {:error, any()}

Complete an MFA challenge by providing the one-time password.

Returns the created Session on success.

update_mfa_recovery_codes()

@spec update_mfa_recovery_codes() :: {:ok, map()} | {:error, any()}

Regenerate MFA recovery codes (requires a completed OTP challenge).

update_name(name)

@spec update_name(String.t()) :: {:ok, map()} | {:error, any()}

Update the current user's display name.

update_password(new_password, old_password \\ nil)

@spec update_password(String.t(), String.t() | nil) :: {:ok, map()} | {:error, any()}

Update the current user's password. old_password is required unless the account has no password.

update_phone(phone, password)

@spec update_phone(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Update the current user's phone number. Requires current password.

update_phone_session(user_id, secret)

@spec update_phone_session(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Complete a phone OTP session (supply userId + secret from the SMS).

update_phone_verification(user_id, secret)

@spec update_phone_verification(String.t(), String.t()) ::
  {:ok, map()} | {:error, any()}

Confirm phone verification using the userId and secret from the verification SMS.

update_prefs(prefs)

@spec update_prefs(map()) :: {:ok, map()} | {:error, any()}

Replace the current user's preferences object.

update_push_target(target_id, identifier)

@spec update_push_target(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Update a push notification target's device token.

update_recovery(user_id, secret, password)

@spec update_recovery(String.t(), String.t(), String.t()) ::
  {:ok, Appwrite.Types.Token.t()} | {:error, any()}

Complete the password reset flow.

Call this with the userId and secret query parameters from the recovery email link, plus the user's chosen new password.

Parameters

  • user_id (required)
  • secret (required) — the reset token from the email link
  • password (required) — the new password (8–256 chars)

update_session(session_headers, session_id)

@spec update_session(map(), String.t()) :: {:ok, map()} | {:error, any()}

Extend or update an existing session.

update_status()

@spec update_status() :: {:ok, map()} | {:error, any()}

Block the current account (sets status to false).

update_verification(user_id, secret)

@spec update_verification(String.t(), String.t()) :: {:ok, map()} | {:error, any()}

Confirm email verification using the userId and secret from the verification link.