Skip to content

AppCheck token refresh is triggering permission-denied in existing Firestore snapshot listeners #7116

Closed
@harrisonlo

Description

@harrisonlo

Describe your environment

  • Operating System version: macOS Monterey 12.6.3
  • Browser version: Chrome 110
  • Firebase SDK version: 9.17.2
  • Firebase Product: AppCheck, Firestore

Describe the problem

When the browser tab is left open for an extended period of time, the app regularly detects permission-denied errors from Firestore snapshot listeners. Here is a screenshot in which you may see a pattern:

Screen Shot 2023-03-13 at 7 17 50 AM

These errors mostly have a 55 minutes interval, which I suspect is due to the token refresh from AppCheck, which I recently enforced. There are 5~7 active snapshot listeners in the app, not all of them trigger this all the time. As you can see in the screenshot, only a pair of them consistently did. However, all of them erroneously triggered the error at one point.

Depending on the app logic, it sometimes breaks the app. i.e. when you don't have permission, you can't access a document.

Also I should clarify, the user does have permission. Refreshing always solves the permission issue.

Steps to reproduce:

Enforce Firestore AppCheck in the Firebase console, then open a page with a Firestore listener for 55 minutes to an hour until the AppCheck token refreshes.

Relevant Code:

This error is captured in the third argument of the Firestore onSnapshot hook.

const unsubscribe = onSnapshot(
    query(...),
    snapshot => {...},
    error => capture(error)
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions