Introducing a new way to review your PRs.

Read the announcement

appwrite / sdk-for-react-native

[READ ONLY] Official Appwrite React Native SDK 💙 ⚛︎

View on GitHub

24 documents · Updated Nov 18, 2026

docs / account-authentication-and-security

Account authentication and security

The Account service is the user-facing boundary for identity, sign-in, account settings, and account security. It lets an app create and read the current user, manage sessions and account-switching devices, recover access, verify contact details, use MFA and passkeys, manage linked provider access, review security records, and register devices for push messages. It works with the wider identity and collaboration services, while team access, message delivery, and organization access are covered by teams and memberships, messaging subscribers, and organizations and installations.

Account lifecycle

Account profile

The Account service creates a user and returns the current authenticated user with get. It also updates the user’s name, email, password, phone number, preferences, MFA setting, and status. These operations keep user-owned profile data and account access under one user session.

Email and phone changes reset the related verification state. The service does not send the new verification message as part of the change, so the app must start the matching verification flow when needed. Blocking an account prevents access without deleting the user record.

The account preference object is replaced as a whole when it is updated. Treat it as one user-owned value rather than as a set of fields that the service merges.

References: src/…/account.ts• L15-85 src/…/account.ts• L796-928 src/…/account.ts• L2617-2723 src/…/account.ts• L3249-3642 src/…/account.ts• L5433-5498

OAuth consents

An OAuth consent records the permission that the current user gave to a third-party app. The Account service lets the user list and inspect consents, review the token families issued under a consent, revoke one token family, or revoke the full consent.

Revoking a full consent stops all token families issued under it and requires the third-party app to ask for consent again. Revoking one token family stops only that family. Token secrets are not returned through these views.

References: src/…/account.ts• L249-794

Sign-in paths

The service supports several ways to begin authentication. Some paths create a session at once. Others create a short-lived token or redirect that the app must exchange for a session.

Sign-in pathFirst resultSession step
Email and passwordA sessionNo extra exchange
Anonymous accessA session for an anonymous accountThe account can later gain an email and password
Email one-time codeA token sent by emailExchange userId and secret with createSession
Magic URLA token and an app redirectExchange the returned userId and secret with createSession
Phone one-time codeA token sent by SMSExchange userId and secret with createSession
Browser OAuth providerA browser redirect URL or token redirectUse the returned token values to create a session when the token form is used
Native Apple or Google ID tokenA sessionNo browser or token exchange
PasskeyA verified sign-in tokenExchange its userId and secret with createSession

Email and phone token paths can create a new user when the contact value is not already linked to an account. OAuth sign-in can attach to the active account or to a matching existing email, or create a user when no match exists. OAuth providers must be enabled for the project, and redirect URLs must belong to the project’s registered platforms.

Native ID-token sign-in is separate from browser OAuth. It accepts a verified Apple or Google token and checks its configured audience and nonce where required. It can store a provider access token for later client use, but it does not provide a provider refresh token. Browser OAuth is the option when Appwrite must renew provider access.

Passkey sign-in uses a short-lived browser credential challenge. The returned token can be exchanged for a session, and successful user verification also satisfies MFA for that session.

The optional security phrase on email-based token flows gives the app a value to compare with the phrase shown to the user. This adds a check that the user is using the expected message.

The following diagram shows how direct, token-based, redirect-based, native, and passkey sign-in paths lead to an authenticated session.

flowchart LR
    A[Email or phone token] --> C[User ID and secret]
    B[Magic URL or OAuth token redirect] --> C
    P[Passkey credential] --> C
    C --> D[Create session]
    E[Email and password] --> F[Session]
    G[Anonymous sign-in] --> F
    H[Native Apple or Google ID token] --> F
    D --> F

References: src/…/account.ts• L4249-5069 src/…/account.ts• L4457-4669 src/…/account.ts• L4794-4931 src/…/account.ts• L5851-6480

Session state

A session represents an active sign-in on a device or client. The service lists all active sessions, reads one session, extends a session, logs out one session, or removes every session from the account.

Account-switching devices group sessions for one browser or app install. Once a device exists, new sessions can join it so one client can hold several accounts and switch the active account. The service can create, inspect, delete, and switch sessions on such a device. The device secret is kept in a cookie and rotates when a session joins or becomes active, so a client must not keep using an older copy.

The special session ID current refers to the device session used by the request. A session created through browser OAuth can refresh its provider access token when it is extended. Native ID-token sign-in does not give Appwrite a provider refresh token. The service also creates a short-lived JWT for server-side API use. Logging out invalidates that JWT during its validity window.

The default account limit is 10 active sessions. A sign-in flow can therefore fail when an account has reached its session limit until an existing session is removed.

References: src/…/account.ts• L796-1184 src/…/account.ts• L1098-1165 src/…/account.ts• L4085-5450

Recovery and verification

Recovery and verification use two-step token flows. The first step sends a message and produces a temporary token. The second step consumes the user ID and secret from that flow to complete the action.

FlowStartCompleteValidity
Password recovery linkSend an email with a reset linkSet a new password with userId and secretLink is valid for 1 hour
Password recovery codeSend a six-digit email codeSet a new password with userId and secretCode is valid for 15 minutes
Email link verificationSend a verification emailConfirm the email with userId and secretLink is valid for 7 days
Email code verificationSend a six-digit email codeConfirm the email with userId and secretCode is valid for 15 minutes
Phone verificationSend a verification SMSConfirm the phone with userId and secretCode is valid for 15 minutes

Recovery and email link verification redirect the user to an app URL. Code-based recovery and email verification do not need a hosted verification page, so they support mobile and desktop clients. Redirect URLs must use a hostname registered as a project platform. This boundary prevents an untrusted site from receiving the token through an open redirect.

The recovery endpoints apply the project’s password rules after token verification. A rejected password leaves the current password unchanged and keeps the recovery token usable. The verification flows confirm ownership of the current email or phone value. They do not replace the account update step that changes that value.

The optional security phrase on code-based email flows gives the user a value to compare with the phrase shown in the email. This helps the app detect an unexpected or unsafe message before the user uses the code.

References: src/…/account.ts• L3644-4083 src/…/account.ts• L6482-7165

MFA controls

Multi-factor authentication (MFA) adds a second check after the first sign-in step. The Account service enables or disables MFA, adds and verifies a time-based authenticator, lists usable factors, and removes an authenticator.

After sign-in, the app selects an available factor and starts an MFA challenge. It completes the challenge with the resulting challenge ID and one-time password. A successful completion returns the session that the user can use. The available challenge factors are email, phone, totp, recoveryCode, and custom.

Recovery codes provide a backup factor. The app generates them after setting up an authenticator, reads them through the protected recovery-code operation, and can replace them later.

The following diagram shows the relationship between authenticator setup, account MFA, and sign-in challenge completion.

flowchart TD
    A[Add authenticator] --> B[Verify one-time password]
    B --> C[Enable MFA]
    C --> D[Sign in]
    D --> E[Create MFA challenge]
    E --> F[Submit one-time password or recovery code]
    F --> G[Authenticated session]
    B --> H[Generate recovery codes]
    H --> E

References: src/…/account.ts• L1278-2614

Passkey credentials

Passkeys provide a passwordless sign-in method and a strong user-verification method. The service supports registering, verifying, listing, renaming, reading, and removing the current user’s passkeys.

Registration starts with a server challenge and completes with the browser credential. Sign-in follows the same pattern: the app gets a challenge, returns the credential, and exchanges the resulting token for a session. Registration and sign-in challenges are short-lived and single use. Sensitive passkey changes require a recent sign-in or completed MFA challenge.

References: src/…/account.ts• L2725-3247 src/…/account.ts• L6243-6383

An identity is a provider account linked to the current user. The service lists the user’s identities and can remove one by its identity ID. Query support lets the app filter the list by provider or provider account data and control whether the total count is calculated.

Removing an identity changes how the user can sign in. The app must keep another suitable sign-in path available before it removes a provider link.

References: src/…/account.ts• L930-1096

Security activity records

The current Account service exposes session views and OAuth consent records for account security review. It does not expose a separate general security-log read operation in this client boundary, so these views must not be treated as a complete activity log.

References: src/…/account.ts• L249-794 src/…/account.ts• L4085-4189

Push targets

A push target connects the current account session to a device destination for messages. Registration stores a target identifier, a device or delivery token, and an optional messaging provider. It can also use an app bundle ID and APNs environment to select a configured Apple push provider when no provider ID is given.

A session holds one push target per provider. Registering an existing target for that provider updates and returns it instead of creating a second target. This supports device-token rotation without duplicate delivery. The app can replace a target’s identifier or delete the target. Deletion stops push delivery to that device. Provider selection connects this account feature to the broader messaging subscribers model.

References: src/…/account.ts• L5500-5849

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to contact updates must remain aligned with the matching email and phone verification start and completion flows. A changed contact value is unverified until the new flow completes.
  • Changes to token sign-in must preserve the userId and secret hand-off from email, magic URL, phone, passkey, and OAuth flows to createSession.
  • Changes to native ID-token sign-in must stay aligned with the Apple and Google provider set, nonce checks, audience settings, and the separate browser OAuth flow.
  • Changes to passkey challenge or credential handling must preserve the browser credential exchange and its short validity and single-use rules.
  • Changes to MFA factor names must stay aligned between the factor values, challenge creation, and challenge completion flows.
  • Changes to session deletion must preserve the distinction between the current session, one named session, and all sessions. JWT behavior also depends on logout state.
  • Changes to account-switching devices must preserve device-cookie rotation, session attachment, active-session switching, and the fact that device deletion signs out every session it holds.
  • Changes to OAuth consent revocation must preserve the difference between revoking one token family and revoking the full consent.
  • Changes to push target ownership, per-provider uniqueness, bundle and environment routing, or provider selection must remain compatible with the messaging provider contract.
  • Changes to code-based recovery or verification must preserve the separate userId and secret hand-off, token lifetime, password policy, and optional security phrase behavior.

Important failure modes

TriggerConsequenceGuard
A recovery or verification redirect uses an unregistered hostnameThe service rejects the flow or the token cannot safely return to the appUse a URL whose hostname is in the project platform list
A user changes email or phone and the app does not start verificationThe new contact value remains unverifiedStart the matching email or phone verification flow after the update
A recovery password violates the project password rulesThe password stays unchanged and the token remains usableApply the project rules before retrying the same recovery token
A sign-in creates a session after the account reaches its active-session limitSession creation failsList sessions and remove an unused session before retrying
The app completes MFA without the challenge ID or with an invalid one-time passwordThe sign-in does not produce an authenticated sessionKeep the challenge ID and submit a valid code for the selected factor
A passkey challenge expires, is reused, or receives an invalid credentialRegistration or sign-in does not completeStart a new challenge and return the matching browser credential once
The native ID token has an unsupported audience or a required nonce does not matchNative sign-in is rejectedEnable native sign-in for the provider and pass the expected client ID and nonce
The app removes the only usable identity or sign-in pathThe user may lose access through that providerConfirm another sign-in path before deleting an identity
An app revokes the full OAuth consent when it only needs to remove one deviceAll token families under the consent stop workingRevoke the specific token family when the wider consent must remain
A client uses an old device or session secret after a device join or account switchRequests can fail because the secret was rotatedRead the current cookie or replace the stored secret after each session response
An app deletes an account-switching device to remove one sessionEvery session on that device is signed out and its cookies are clearedDelete one account session when the other device sessions must remain
A push target uses a stale identifier or the wrong APNs bundle and environmentThe device stops receiving push messagesRefresh the target and use the provider configuration that matches the device
A code-based recovery or verification code expires or is reusedThe account action does not completeRequest a new code and complete the matching flow within its validity period

Key files

FileWhy to read it
src/…/account.tsPrimary Account service boundary for profile data, sign-in, sessions, account-switching devices, recovery, verification, MFA, passkeys, identities, OAuth consents, JWTs, and push targets
src/…/authentication-factor.tsDefines the factor names that the MFA challenge flow accepts
src/…/authenticator-type.tsDefines the authenticator type used during MFA setup
src/…/id-token-provider.tsDefines the native ID-token providers supported by native sign-in
src/…/o-auth-provider.tsDefines the OAuth providers available to browser OAuth session and token flows