When using Firebase Authentication's firebase.auth().getRedirectResult()
method, is there a way to detect if we should expect a result (or if the user came from a redirect login)?
There's a delay in when this method is run and when a success/error callback occurs. I'd like to show some loading state as soon as possible and don't see any methods in the documentation, like isRedirectResult
.
For example, I'd like something like this (psuedo-code)
button.onclick = () => {
firebase.auth().signInWithRedirect(provider);
}
if (isFromRedirectPage) { // how do i do this??
button.loading = true;
await firebase.auth().getRedirectResult();
button.loading = false;
} else {
button.show();
}
Could be confusion around what the method was called, but I was able to use firebase.auth().onAuthStateChanged((user) => {...})
to solve this after all.
This method calls the callback function even if the user is not logged in, so I use that to determine loading state:
loading = true;
firebase.auth().onAuthStateChanged((user) => {
loading = false;
if (!user) {
// show login button
} else {
// hide login button
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.