Social Login using angular

In this topic you will learn how to login with Facebook and Google in the angular app using the angularx-social-login npm package. It is easy and fastest way to login in application using social network platform .

1 Install Angular
install it with the below command:

npm install -g @angular/cli

2. Create new project

ng new projectname

3. Now Install the angular social login plugin using cmd

npm install angularx-social-login

4. Import social library in the app.module.ts file and add code in provider array

import { SocialLoginModule, SocialAuthServiceConfig } from 'angularx-social-login';
import {
} from 'angularx-social-login';

 imports: [

providers: [
      provide: 'SocialAuthServiceConfig',
      useValue: {
        autoLogin: true,
        providers: [
            id: GoogleLoginProvider.PROVIDER_ID,
            provider: new GoogleLoginProvider('',
             // scopes : environment.auth.scopes,
              prompt : 'none'   // '' | 'none' | 'consent' |  'select_account'

            id: FacebookLoginProvider.PROVIDER_ID,
            provider: new FacebookLoginProvider('1442566939524545')
        onError: (err) => {
      } as SocialAuthServiceConfig,

5 Create social login function in login.component.ts

import { FacebookLoginProvider,GoogleLoginProvider, SocialAuthService, SocialUser } from 'angularx-social-login';

 user:SocialUser | undefined;
  loggedIn: boolean | undefined;
  isLoggedin?: boolean = undefined;

 constructor(private backend: BackendService, private token: TokenService, private router: Router, private Auth: AuthService, private ssoauthService:SocialAuthService) {

  ngOnInit(): void {
      this.user = user;
      this.loggedIn = (user != null);
      this.isLoggedin = user != null;
      console.log("Login User = " + +;

signInWithFB(): void { //Facebook Login

  signWithGoogle():void{console.log("googlesignin"); //for google sign in

  signOut():any{ //for google out

  refreshToken(): void {

6) Create Login button in login.component.html

<button class="btn btn-primary btn-social-icon btn-google mx-1" (click)="signWithGoogle()">
                <span class="fab fa-google">SignIn With Google</span>

              <button type="button" (click)="signInWithFB()" class="btn btn-primary btn-block">Signin with Facebook</button>

 <div *ngIf="isLoggedin === true">
          <button type="button" (click)="signOut()" class="btn btn-primary">Sign Out</button>

Create Facebook App ID

Follow the below recommended steps for creating Facebook App Id -:

A. Visit on

B. Click on “Create App” button

C. Select an app type and click on next

D. Add the Display name and app contact email then click on the “Create App” button.

E. Click on “set up” button in Facebook Login card.

F. Click on “WWW Web” icon

G. Enter “Site URL” and click on “Save” then “Continue” button

H. Click on “Dashboard” in left side and can copy your App Id

Create a Google Client ID

  1. Go to :
  2. Click Credentials on left side then click on “CREATE CREDENTIALS” on top and select “OAuth client ID”

3. Select “Web Application” inside Application Type

4. Enter app Name and enter URL’s then Click on “CREATE” button

5. Copy Your Client ID.

Complete Code for Social Login

Leave a Reply

Your email address will not be published. Required fields are marked *