According to https://firebase.google.com/docs/auth/admin/custom-claims#propagate_custom_claims_to_the_client one can update the claims locally by calling currentUser.getIdToken(true).
In flutter I guess one should be able to do the same with:
final user = await FirebaseAuth.instance.currentUser();
await user.getIdToken(refresh: true);
Sadly this seems not reflected when I try to use firestore. After updating claims through a cloud function and then calling getIdToken as above it will still not have the claims correct in firestore rules. It returns "PERMISSION_DENIED". When I then close the app and reopen the app, firestore rules go through correctly though (seems like claims then get updated).
Additional problem is, that I can not see if the claims locally got updated or not because the API for that is not yet implemented (see separate issue #20238).
Now the issue is: How can force propagation of the claims in flutter? The way the documentation says seems not to be correct. Is this a bug in the documentation or a bug in the flutter client?
flutter: v0.8.2
cloud_firestore: 0.8.1
firebase_auth: 0.5.20
After further investigations it seems to only be happening on Android. On iOS the claims seem to be updated nicely (seems to work even without calling getIdToken() ). So this problem seems Android specific.
@pboos
The issue at https://github.com/flutter/flutter/issues/22801 has been closed and moved here. Future collaboration on this issue will be done here.
Any update on this issue? Or any suggested workaround for me to get updated claim for an already logged-in user?
Thanks,
Please update, facing the same issue.
Hey 馃憢
Our rework of the firebase_auth plugin as part of the FlutterFire roadmap was published over a week ago with a ton of fixes and new features.
Please could you update to the new version as this feature is now supported. If you have any problems with this feature or the updated plugins please raise a new GitHub issue.
For help migrating to the new plugins please see the new migration guide: https://firebase.flutter.dev/docs/migration
Most helpful comment
Any update on this issue? Or any suggested workaround for me to get updated claim for an already logged-in user?
Thanks,