Last active
March 9, 2021 17:28
-
-
Save Chriz76/5f23b6e0d784cffa877b139a82a53b42 to your computer and use it in GitHub Desktop.
http request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { SocialAuthService } from 'angularx-social-login'; | |
import { SocialUser } from 'angularx-social-login'; | |
import { GoogleLoginProvider } from 'angularx-social-login'; | |
import { HttpClient } from '@angular/common/http'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
user: SocialUser | null; | |
constructor(private authService: SocialAuthService, private http: HttpClient) | |
{ | |
this.user = null; | |
this.authService.authState.subscribe((user: SocialUser) => { | |
console.log(user); | |
if (user) { | |
this.http.post<any>('https://localhost:5001/user/authenticate', { idToken: user.idToken }).subscribe((authToken: any) => { | |
console.log(authToken); | |
}) | |
} | |
this.user = user; | |
}); | |
} | |
signInWithGoogle(): void { | |
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID).then((x: any) => console.log(x)); | |
} | |
signOut(): void { | |
this.authService.signOut(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment