Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebaseAuth GoogleAuthProvider() signInWithRedirect

I've a authentication Google with redirect in my app, and I would like just redirect when authentication is completely finished. But the promise is not working

 function loginGoogle() {
        var provider = new firebase.auth.GoogleAuthProvider();
        firebase.auth().signInWithRedirect(provider);
        firebase.auth().getRedirectResult().then(function (result) {
            // This gives you a Google Access Token. You can use it to access the Google API.
            if (result.credential) {
                var token = result.credential.accessToken;
                console.log('token ' + token);
            }
            // The signed-in user info.
            var user = result.user;
            console.log('user ' + user);
            // if success redirect to
            $state.go('maps-fullwidth');

            // ...
        }).catch(function (error) {
            // Handle Errors here.
            var errorCode = error.code;
            console.log(errorCode);
            var errorMessage = error.message;
            // The email of the user's account used.
            console.log(errorMessage);
            var email = error.email;
            console.log(email);
            // The firebase.auth.AuthCredential type that was used.
            var credential = error.credential;
            console.log(credential);
            // ...
        });
    }

Thanks.

like image 390
Yseult Fran Avatar asked Oct 24 '16 13:10

Yseult Fran


Video Answer


1 Answers

Move the getRedirectResult() call out of your loginGoogle() function. getRedirectResult() should be called on page load. An example of this in action can be found here:

https://github.com/firebase/quickstart-js/blob/master/auth/google-redirect.html

like image 87
Channing Huang Avatar answered Nov 09 '22 02:11

Channing Huang