firebase google yolo code example

Example: firebase google yolo

//Angular
//index.html
<body>
  <script src="https://smartlock.google.com/client"></script>
  <app-root></app-root>
</body>

//the top of app.component.ts
declare var googleyolo: any;

//Constructor of app.component.ts
constructor(firebase: AngularAuthFirebase){}
//ngOnInit()
const hintPromise = googleyolo.hint({
       supportedAuthMethods: [
          "https://accounts.google.com"
       ],
       supportedIdTokenProviders: [
       {
          uri: "https://accounts.google.com",
          clientId: "YOUR_GOOGLE_CLIENT_ID"
       }
      ]
    }).then((credential) => {
       if (credential.idToken) {
    // Initialize firebase Auth credential with Google ID token
    // obtained from googleyolo.
    const cred = firebase.auth.GoogleAuthProvider.credential(credential.idToken);
    // Sign in with
    return firebase.auth().signInWithCredential(cred);
  }
  throw new Error;
}).then((result) => {
  // User signed in.
}).catch((error) => {
  // Handle error.
});
});

Tags:

Misc Example