nss-evening-cohort-06 / pinterest-cereal-killers

pinterest-cereal-killers created by GitHub Classroom
1 stars 0 forks source link

Authentication Setup #7

Open GinaAntonini opened 6 years ago

belv2c commented 6 years ago

In AuthService.js:

app.service("AuthService", function() {
    const authenticateGoogle = () => {
        const provider = new firebase.auth.GoogleAuthProvider();
        return firebase.auth().signInWithPopup(provider);
    };

const isAuthenticated = () => {
    return firebase.auth().currentUser ? true : false; 
};

const logout = () => {
    firebase.auth().signOut();
};

return {authenticateGoogle, isAuthenticated, logout};

});
belv2c commented 6 years ago

In LoginCtrl.js:

app.controller("LoginCtrl", function($location, $rootScope, $scope, AuthService) {
    $scope.authenticate = () => {
        AuthService.authenticateGoogle().then((result) => {
            $rootScope.uid = result.user.uid;
            $scope.$apply(() => {
                $location.url("/contacts/view");
            });
        }).catch((err) => {
            console.log("error in authenticateGoogle", err);
        });
    };
});