我一直在努力为使用电子邮件和密码注册的用户获取 displayName 的价值,它总是给我null
。
这是我的 AuthService
@Injectable()
export class AuthService {
authState: any = null;
user$: Observable<firebase.User>;
constructor(private afAuth: AngularFireAuth,
private db: AngularFireDatabase,
private route: ActivatedRoute,
private userService: UserService) {
this.user$ = this.afAuth.authState;
this.afAuth.authState.subscribe((auth) => {
this.authState = auth;
});
}
signUp(email, password) {
this.afAuth.auth.createUserWithEmailAndPassword(email, password)
.then((user) => {
this.authState = user;
})
.catch(error => console.log(error));
}
private updateUserData(): void {
const path = `users/${this.currentUserId}`; // Endpoint on firebase
const data = {
email: this.authState.email,
name: this.authState.displayName
};
this.db.object(path).update(data)
.catch(error => console.log(error));
}
&#13;
这是我的注册。
export class SignupComponent implements OnInit {
constructor(private auth: AuthService,
private user: UserService) { }
ngOnInit() {
}
onSignup(form: NgForm) {
const user = firebase.auth().currentUser;
user.updateProfile({
displayName: form.value.username,
photoURL: 'https://example.com/jane-q-user/profile.jpg'
})
.then(function(response) {
const displayName = user.displayName;
}, function(error) {
console.log(error);
});
const name = form.value.username;
const email = form.value.email;
const password = form.value.password;
this.auth.signUp(email, password);
&#13;
我不知道如何使用从signUp
表单中获取的名称,并将其设置为displayName
以获取 firebase.user