Firebase Authentication is easy to start and surprisingly easy to outgrow without an explicit architecture. This guide provides a reusable checklist for choosing providers, managing sessions, designing custom claims and roles, adding multi-factor authentication, linking accounts, migrating users, and handling recovery without weakening security.
Overview
A sound Firebase Authentication design separates four concerns: how a user proves their identity, how the client maintains a session, how the backend authorizes actions, and how the product handles account changes over time. Treating these as separate decisions makes future changes safer.
Firebase Authentication can support email and password accounts, federated providers, phone-based sign-in, anonymous sessions, and other provider options available to the project and platform. The right choice depends on the application’s audience, recovery requirements, regulatory context, and the level of assurance needed for sensitive actions. Start with the smallest provider set that meets the product requirement. Each additional provider creates another account-linking, recovery, testing, and support path.
Authentication answers “who is this user?” Authorization answers “what may this user do?” Use Firebase Authentication for identity, then enforce access through Firestore or Realtime Database Security Rules and trusted server-side code. A signed-in user should not automatically receive permission to read every document or call every function. For data structure decisions that affect authorization, see the Firestore Data Modeling Guide.
For every provider and account type, document the expected lifecycle: sign-up, sign-in, email verification where applicable, sign-out, password or credential recovery, account deletion, provider linking, and changes to email addresses or phone numbers. This lifecycle documentation is more valuable than a provider list because it exposes gaps before they reach production.
Checklist by scenario
New web or mobile app
- List the user types and the actions each type must perform.
- Choose providers based on user expectations and recovery needs, not convenience alone.
- Decide whether anonymous authentication is necessary. If it is, define how an anonymous account becomes a permanent account and what happens to its data.
- Configure authorized domains, platform settings, redirect behavior, and provider credentials for each environment.
- Keep development, staging, and production projects distinct where practical, and use the Firebase Emulator Suite for local auth and rules testing. The Firebase Emulator Suite Guide covers a repeatable local workflow.
- Write tests for signed-out, signed-in, unverified, verified, and unauthorized states.
Web session management
- Choose the intended persistence behavior: users may expect to remain signed in across browser restarts, while shared or sensitive devices may require a session that ends more readily.
- Make loading state explicit. Do not render protected data while the application is still determining whether a session exists.
- Subscribe to the authentication state observer once at the application boundary and clean up listeners where the framework requires it.
- Handle expired or refreshed tokens without treating a temporary loading state as a signed-out state.
- Do not store passwords, refresh tokens, or raw authentication tokens in application databases or logs.
Role-based access with custom claims
- Define a small role vocabulary, such as
admin,editor, andmember, before adding claims. - Set custom claims only from trusted server-side code, such as an administrative process or Cloud Function. Never accept a role supplied by the client.
- Use claims for compact authorization facts, not for a complete profile, team directory, or rapidly changing application state.
- Enforce the claim in Security Rules and repeat the authorization check in privileged server code.
- Plan how a role change reaches an existing session. A user may need to obtain a refreshed ID token before a newly granted or removed claim is reflected on the client.
- Record who granted or removed an elevated role and when, using an appropriate audit trail that does not expose credentials.
Account linking and multiple providers
- Decide whether one person should have one account with several linked providers or separate accounts per provider.
- When a sign-in attempt matches an existing email, provide a deliberate linking or recovery path rather than silently creating a second profile.
- Require the appropriate recent authentication step before sensitive account changes.
- Define which profile data wins when two providers supply different display names, photos, or email values.
- Test linking, unlinking, sign-in after unlinking, and the case where a provider credential is already attached to another user.
MFA, recovery, and migration
- Use multi-factor authentication for accounts or actions that justify stronger assurance, and clearly explain enrollment, challenge, lost-factor recovery, and factor removal.
- Protect recovery flows as carefully as sign-in flows. Recovery should not become an unintended bypass around MFA or email verification.
- For a migration from another identity system, map stable user identifiers, verified status, provider relationships, and account metadata before importing users.
- Run a small migration rehearsal, define rollback or support procedures, and test users with duplicate emails, missing recovery details, and legacy password formats.
- Keep migration credentials and import files out of source control and application logs.
What to double-check
Before releasing an authentication change, inspect the boundary between the client, Firebase Authentication, Security Rules, and trusted backend code. A client-side route guard improves user experience, but it is not an access-control boundary. The real decision must be enforced where data is read, written, or processed.
- Provider configuration: Verify provider credentials, redirect URLs, authorized domains, consent text, and environment-specific settings.
- Email state: Decide which features require a verified email and enforce that requirement in rules or backend logic rather than relying only on a disabled button.
- Token behavior: Confirm which code reads the current user, which code obtains an ID token, and how token refresh or revocation-related errors are handled.
- Claims: Check that claims are issued only by trusted code, remain small, and are tested for both positive and negative cases.
- Rules: Test ownership, role checks, tenant boundaries, missing documents, and attempts to change protected fields. Never use a profile field written by the user as the sole source of authorization truth.
- Account deletion: Define whether related Firestore documents, Storage objects, subscriptions, and external records are removed, anonymized, or retained under a documented policy.
- Observability: Log useful event context without logging passwords, raw tokens, recovery links, or unnecessary personal data.
Keep auth tests close to deployment checks. A repeatable release process is easier to maintain when authentication configuration, rules, and backend code are reviewed together; the Firebase CI/CD and Deployment Guide provides related deployment guidance.
Common mistakes
Putting roles in user-editable data
A document field such as role: "admin" is not an authorization system if the user can write that document. Store authorization facts in a trusted mechanism and deny writes to protected role fields.
Assuming a claim changes immediately
Custom claims are carried in authentication tokens. After changing a claim, the current client may continue using an older token until it refreshes. Design the user experience and backend checks around that transition instead of promising instant access changes without testing.
Creating duplicate accounts
Offering email, Google, Apple, phone, or other providers without an account-linking strategy can produce multiple profiles for one person. Decide how conflicts are identified and give users a safe, understandable resolution path.
Relying only on frontend protection
Hiding an admin screen does not protect admin data. A user can call application endpoints or attempt direct database access independently of the interface. Enforce every sensitive operation with Security Rules or trusted server code.
Making recovery an afterthought
Users lose devices, forget passwords, change email addresses, and lose access to second factors. Document the recovery path before launch, test it with real staging accounts, and make support procedures consistent with the guarantees your system provides.
Mixing environments
Testing a provider callback or account deletion flow against production is an avoidable risk. Use project aliases and deployment controls deliberately; the Firebase CLI Guide can help organize environment-specific workflows.
When to revisit
Review this authentication architecture before each major release, seasonal planning cycle, or change to identity providers, account roles, data tenancy, or recovery policy. Also revisit it when workflows or tools change, when a new mobile or web client is introduced, or when a service begins handling more sensitive information.
Use this short review sequence:
- Compare the current provider and role configuration with the product’s actual user journeys.
- Run emulator and integration tests for sign-in, linking, claims, MFA, recovery, deletion, and unauthorized access.
- Review Security Rules and backend authorization paths for newly added collections, functions, or fields.
- Inspect authentication errors and support cases for recurring confusion or failed recovery.
- Update the architecture record, migration plan, and release checklist before changing production configuration.
Authentication is not a one-time setup task. A small, documented provider strategy, explicit session behavior, trusted authorization checks, and tested recovery paths give Firebase applications a foundation that can adapt as the product and its workflows change.