I want to write a helper function that returns the firebase user token id. I managed to get the firebase token from this approach but I am having trouble in returning the promise value (token id) from the observer function of onAuthStateChange
to the functions that calls the getToken()
helper method. I am very new promises and would greatly appreciate any help.
Here is what I got so far.
export function getToken (){
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
user.getIdToken().then(token => {
return token // Managed to get the valid token
})
} else {
}
});
}