All entries

    Firebase Email Verification Passed, but Comment Writes Still Fail: Test the Token

    Email verified but Firestore writes still fail? Separate Firebase user state, ID-token claims and database rules. Refresh deliberately and keep rules strict.

    A pixel-art email verification badge and a separate identity-token card approach a protected comment database gate.
    Original GPT-generated pixel-art editorial illustration; conceptual artwork, not a product screenshot or test result.

    A verified-email screen and a Firestore-authorised request are not the same observation. Your UI can show updated account state while the request still uses an older ID token, or the write can fail a different rule entirely. Diagnose user state, token claims, project identity and the complete rule predicate before relaxing database permissions.

    Identify which state the UI is displaying

    A local component may cache a user object or a separate verified flag. Confirm that the application reads current Firebase account state rather than a value written by an earlier screen. If the user completed verification in another tab, the original page may not have updated automatically in the way your UI assumes.

    Do not use a client-written verified field as the authority for database access. Security rules should rely on trusted authentication claims and the intended resource checks. A person must not be able to grant themselves a privileged state by editing a profile document.

    Refresh deliberately after the verification flow

    The JavaScript User API distinguishes reloading user data from retrieving an ID token with forced refresh. A typical client check reloads the current user, confirms the account state and requests a fresh token before retrying the intended operation. Handle errors and sign-out transitions rather than assuming a user always exists.

    Never log the returned token. If you inspect claims in a controlled development environment, retain only the non-sensitive assertion needed for the test. Do not paste a complete token into a public issue or article.

    TypeScript — illustrative client check, not complete comment logic
    const user = auth.currentUser;
    if (!user) throw new Error('Sign in first');
    await user.reload();
    if (!user.emailVerified) throw new Error('Verify your email first');
    await user.getIdToken(true);
    // Now attempt the authorised write; keep server-side rules enforced.
    EXPLAINED / SEQUENCE

    Verification must reach the request's claims

    A simplified client flow. Actual permission also depends on the rest of the deployed rules.

    Account

    1. Email action

      The person completes the provider's verification flow.

    2. Reload and token refresh

      The client deliberately refreshes relevant account and token state.

    Database

    1. Authenticated request

      Firestore evaluates claims on the request, not a UI label.

    2. Full rule predicate

      Ownership, field validation and other constraints still apply.

    THE KEY DISTINCTION

    Refreshing a token can fix stale claims; it cannot make an invalid or unauthorised write valid.

    Author-created explanatory diagram. Arrows show the process described in the article, not measured performance.

    Check the project and identity boundary

    Confirm Auth and Firestore use the intended Firebase project and app configuration. A development client connected to one project and rules deployed to another can produce confusing results. Also check whether the current signed-in account is the one that completed verification.

    A successful Google sign-in and an email/password flow can have different user journeys. Do not infer a particular claim from the button label alone; inspect the trusted authentication state in a safe test. Keep account identifiers out of public diagnostics.

    Read the complete rule predicate

    An email_verified requirement is only one possible condition. The write may also need the correct owner, allowed fields, valid text length, server timestamp or an existing parent resource. A fresh token cannot repair a malformed document or another user's target.

    Scroll the table horizontally to see all columns.

    Read the complete rule predicate
    BoundaryTest fixtureWhat a failure suggests
    Signed outNo authenticated identitySign-in is required
    Signed in, unverifiedVerified claim falseVerification gate should reject
    Verified, valid own writeCorrect claims and permitted dataIntended happy path should pass
    Verified, another ownerDifferent resource ownershipAuthorisation should reject
    Verified, invalid fieldsExtra or malformed dataValidation should reject
    Wrong environmentMismatched project setupConfiguration needs correction

    Use the emulator to isolate rules

    Build disposable fixtures with explicit authentication claims and invented documents. Test both the allowed write and the nearby rejected cases. A rule test that only proves one success does not establish that cross-user access is blocked.

    Keep the deployed rules strict while investigating. Do not temporarily allow all authenticated writes on production to see whether the UI starts working. That changes the security boundary and can expose data while leaving the original client defect unresolved.

    Give the reader a useful recovery state

    If verification is still pending, explain how to complete it and offer a deliberate recheck. If the token refresh or write fails, distinguish a temporary connection problem from permission denied where the SDK supports that distinction. Preserve the draft without repeatedly submitting it in an automatic loop.

    After a successful write, render the confirmed result rather than only an optimistic success message. If optimistic UI is used, reconcile failures visibly. The person should not believe a comment was stored when rules rejected it.

    Verify the whole flow before release

    Test the email action, return to the original page, state refresh, authorised write and an unauthorised counterexample in the intended environment. Passing an emulator test proves rule behaviour under those fixtures; it does not alone prove the live identity configuration. Report both boundaries accurately and keep tokens and personal data out of the evidence.

    Frequently asked questions

    Why can Firestore reject a write after email verification? The request may carry stale claims, use a different project or account, or fail another rule such as ownership or field validation. Inspect the complete request path before changing rules.

    Does reloading the Firebase user force a new ID token? Treat user reload and forced token refresh as separate operations. The User API documents getIdToken with a forceRefresh argument; use it deliberately when claims must be refreshed.

    Should I allow every signed-in user to write to fix this? No. Keep the intended verification, ownership and validation rules. Use emulator fixtures to find the failing predicate and repair the client or rule logic without broadening access unnecessarily.

    FURTHER READING

    Sources

    Technical references checked .

    END OF ENTRY / 162
    Eeshan Singh with Big Ben in London
    BEHIND THE JOURNAL

    Eeshan Singh

    I’m Eeshan Singh Pokharia, an AI Full Stack Developer and CoFounder of UltraFit360. I work across AI features, full-stack product development, and web and mobile experiences—from Figma and frontend interactions to the systems behind them.

    This is an invented comments example, not a copy of TechNightCity's deployed rules or private data. It demonstrates the authentication boundary without exposing user identifiers, email addresses, tokens or production documents.

    Meet the author
    THE CONVERSATION

    Your side of the story.