Firebase user idToken not updating

I am developing an application and using firebase to manage users. I successfully create a user and then successfully launched it.

The problem occurs when I ask for an idToken. I tried

FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
mUser.getToken(true)
    .addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
    public void onComplete(@NonNull Task<GetTokenResult> task) {
        if (task.isSuccessful()) {
            String idToken = task.getResult().getToken();
            // Send token to your backend via HTTPS
            // ...
        } else {
            // Handle error -> task.getException();
        }
    }
});

      

I have also tried

final FirebaseAuth.IdTokenListener handle = new FirebaseAuth.IdTokenListener() {
        @Override
        public void onIdTokenChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser mUser = firebaseAuth.getCurrentUser();
            if(mUser!=null){
                Log.w("User getToken: user :", mUser.getDisplayName());
                mUser.getIdToken(true)
                        .addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
                            public void onComplete(@NonNull Task<GetTokenResult> task) {
                                if (task.isSuccessful()) {
                                    String idToken = task.getResult().getToken();
                                    Log.w("User getToken: ", idToken);

                                } else {

                                }
                            }
                        });
            }
        }
    };

    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    mAuth.addIdTokenListener(handle);

      

when

Log.w("User getToken: user :", mUser.getDisplayName());

      

gets the invoked information I get from the created user, but when

Log.w("User getToken: ", idToken);

      

is called, the token value is always the same. It's weird that this worked until today. I haven't made any changes, so I don't understand why the token I receive is always the same, even if the current user changes.

+3


source to share





All Articles