I'm new to angular, currently implementing Google Sign-In(OAuth). I'm encountering this issue whenever I'm authenticating with Google. Sharing my login and logout functionality. Currently using Angular Social Login i.e Google Login.
signInWithGoogle(): void {
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID).then((data) => {
console.log(data);
}).catch(data => {
this.authService.signOut();
this.router.navigate(['login']);
});
signOut(): void {
this.authService.signOut().then((data) => {
this.router.navigate(['login']);
}).catch((data) => {
});
}
This worked for me.
googleLoginOptions = {
scope: 'profile email'
}; // https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauth2clientconfig
signInWithGoogle(): void {
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID, this.googleLoginOptions ).then((data) => {
console.log(data);
}).catch(data => {
this.authService.signOut();
this.router.navigate(['login']);
});
Refer: https://www.npmjs.com/package/angularx-social-login
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With