Skip to content

Instantly share code, notes, and snippets.

@codediodeio
Last active September 19, 2019 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codediodeio/9b5cc0a26e555a8194760fe5688169a8 to your computer and use it in GitHub Desktop.
Save codediodeio/9b5cc0a26e555a8194760fe5688169a8 to your computer and use it in GitHub Desktop.
Link Anonymous Users to Google/Facebook with AngularFire2 (Angular 4 + Firebase)
import { Component, OnInit } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.scss']
})
export class UserComponent implements OnInit {
user: Observable<firebase.User>;
constructor(private afAuth: AngularFireAuth) { }
ngOnInit() {
this.user = this.afAuth.authState;
}
anonymousLogin() {
return this.afAuth.auth.signInAnonymously()
}
linkGoogle() {
const provider = new firebase.auth.GoogleAuthProvider()
firebase.auth().currentUser.linkWithPopup(provider)
}
linkFacebook() {
const provider = new firebase.auth.FacebookAuthProvider()
firebase.auth().currentUser.linkWithPopup(provider)
}
}
@boskiv
Copy link

boskiv commented Sep 19, 2019

can you share user.component.html ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment