Code for Frontend Implementation
- Please open the project using a suitable Integrated Development Environment (IDE), such as Visual Studio Code or any other appropriate platform.
- Please access the 'app.module.ts' file and input the following code:-
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { SocialLoginModule, SocialAuthServiceConfig, } from '@abacritt/angularx-social-login'; import { GoogleLoginProvider } from '@abacritt/angularx-social-login'; @NgModule({ declarations: [AppComponent], imports: [ BrowserModule, AppRoutingModule, SocialLoginModule, ], providers: [ { provide: 'SocialAuthServiceConfig', useValue: { autoLogin: false, providers: [ { id: GoogleLoginProvider.PROVIDER_ID, provider: new GoogleLoginProvider( '<YOUR CLIENT ID>' ), }, ], onError: (err) => { console.error(err); }, } as SocialAuthServiceConfig, }, ], bootstrap: [AppComponent], }) export class AppModule {} -
Now access the 'component.ts' file and input the following code:-
import { Component, OnInit } from '@angular/core'; import { SocialAuthService } from '@abacritt/angularx-social-login'; import { SocialUser } from '@abacritt/angularx-social-login'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], }) export class AppComponent implements OnInit { user!: SocialUser; loggedIn = false; constructor(private authService: SocialAuthService) {} ngOnInit() { this.authService.authState.subscribe((user) => { this.user = user; this.loggedIn = user != null; }); } } - Now access the 'component.html' file and input the following code.
<asl-google-signin-button *ngIf="!loggedIn" type='icon' size='medium'></asl-google-signin-button> <img *ngIf="loggedIn" src="{{ user.photoUrl }}" referrerpolicy="no-referrer"> <div *ngIf="loggedIn"> <h4>{{ user.name }}</h4> <p>{{ user.email }}</p> </div>If you see the error "asl-google-signin-button' is not a known element"
Then access the 'app.module.ts' and Import GoogleSigninButtonModule like:-import { GoogleSigninButtonModule } from '@abacritt/angularx-social-login';
Access Google Authentication from the server side?
we will write lab this and will be publish soon....
15
