firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

Inconsistent Firestore Access with Custom Claims After getIDTokenForcingRefresh(true)

Open HyenaJeremyLin opened this issue 1 year ago • 5 comments

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!

HyenaJeremyLin avatar Oct 07 '24 01:10 HyenaJeremyLin