Last active
September 19, 2019 14:56
-
-
Save codediodeio/9b5cc0a26e555a8194760fe5688169a8 to your computer and use it in GitHub Desktop.
Link Anonymous Users to Google/Facebook with AngularFire2 (Angular 4 + Firebase)
This file contains hidden or 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, 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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you share
user.component.html
?