I am creating an app in Ionic Vue with Firebase as my backend. I am using Firebase custom claims to assign user roles (‘paid user’ or ‘free user’) and I have set up a cloud function that assign the roles without any problems.
Now I want my app to be able to listen to changes in the custom claims, so that if a free user becomes a paid user, the app will know in realtime. Current I only get the updated custom claim if I reload the app by using onAuthStateChanged like this:
onAuthStateChanged(auth, () => {
if (auth.currentUser) {
auth.currentUser.getIdTokenResult(true).then((idTokenResult) => {
console.log(idTokenResult);
auth.currentUser.subscriber = idTokenResult.claims.subscriber;
});
}
// Run app
});
What would be the best approach to listen for changes when the user gets assigned a new role?