[英]accessing global variables in firebase.auth() typescript
I have declare a vaiable user
outside. 我已经在外面声明了一名可变user
。 But I am unable to access this.user inside firebase.auth().signInWithPopup(provider).then((result) => {
. It is showing undefined. 但是我无法在firebase.auth firebase.auth().signInWithPopup(provider).then((result) => {
访问this.user。它显示为未定义。
import { ...everything } from 'everything';
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
interface User{
email: string;
displayName: string;
uid?: string;
photoUrl?: string;
}
export class LoginPage {
user:User;
constructor(...every) {
}
validateForm(form){
if(form.valid){
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/plus.login');
firebase.auth().signInWithPopup(provider).then((result) => {
const token = result.credential.accessToken;
const userData = result.user;
this.user.email = userData.email;
}).catch(function(error) {
});
}
}
}
}
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
export class LocalAuthService {
constructor(private afAuth: AngularFireAuth) { }
userID: string;
userName: string;
public signUp(email: string, password: string) {
console.log('The service method has been called');
//This will signup your new user. Make sure signup with email is enabled
this.afAuth.auth.createUserWithEmailAndPassword(email, password).catch( function(error) {
console.log('The Error that has occurred is' + error.message);
console.log('The Error that has occurred with error code ' + error.code);
});
this.afAuth.auth.onAuthStateChanged( function(user) {
if (
this.userID = user.uid;
this.userName = user.displayName;
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.