Skip to content

Inconsistent Firestore Access with Custom Claims After getIDTokenForcingRefresh(true) #13830

Closed
@HyenaJeremyLin

Description

@HyenaJeremyLin

Description

I encountered an issue related to Firestore access when using custom claims in our iOS app. Here’s the situation:

  1. Our app calls our server’s API, where the admin sets a custom claim "pair_id" of type String for the user.
  2. After the API call is complete, the app calls getIDTokenForcingRefresh(true) to refresh and retrieve the updated token, which includes the "pair_id" claim.
  3. However, when attempting to access Firestore immediately after obtaining the refreshed token, our access is denied based on the security rules.
  4. Interestingly, if we attempt to access Firestore again after waiting for around 5 seconds, it succeeds without issues.

It seems there is a delay in Firestore recognizing the updated custom claims. Is there a recommended way to adjust this behavior or a workaround to ensure Firestore permissions work immediately after refreshing the token?

I also came across this issue: #1499 Is re-authenticating the only solution for now?

Reproducing the issue

No response

Firebase SDK Version

10.22.1

Xcode Version

16.0

Installation Method

Swift Package Manager

Firebase Product(s)

Firestore

Targeted Platforms

iOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions