How to console the uid. My .ts file is like this:
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { Router } from "@angular/router";
@Component({
selector: 'app-candidate-login',
templateUrl: './candidate-login.component.html',
styleUrls: ['./candidate-login.component.css']
})
export class CandidateLoginComponent implements OnInit {
user: Observable<firebase.User>;
constructor(
public afAuth: AngularFireAuth,
private router: Router) {
this.user = afAuth.authState;
console.log(this.user.uid);
}
ngOnInit() {
}
login(){
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
this.router.navigate(['/registration']);
}
}
But it shows a error like:
C:/MyApp/Join/job-site/src/app/candidate-login/candidate-login.component.ts (23,26): Property 'uid' does not exist on type 'Observable'.
How to solve this? Actually, I want to know the current user. I want to console it.
You have to subsribe to afAuth.authState
like this
this.afAuth.authState.subscribe(user => {
this.user = user;
console.log(this.user.uid);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.