2017-03-06 41 views
2

我可以輕鬆地使用它來創建用戶:如何使用AngularFire2更新Firebase中的用戶?

this.af.auth.createUser({email: email, password: password}); 

但我怎麼修改用戶的詳細信息一旦他們創造的呢? (即:更改密碼或電子郵件地址?)。我會想這樣的事情:

this.af.auth.updateUser({email: email, password: password}); 

但是沒有updateUser方法?

回答

1

我曾經遇到這個問題,還沒有得到一個angularfire2的答案。

這裏是一個天然的火力點方式,我通過這個問題得到。

public auth: any; 
constructor(@Inject(FirebaseApp) firebaseApp: any) { 
    this.auth = firebaseApp.auth(); 
} 

reset(targetEmail: any) { 
    this.auth.sendPasswordResetEmail(targetEmail); 
} 

注:

看來我們不能直接更改密碼,只發送密碼重置EAMIL到目標電子郵件地址。

+0

Pengyy我怎樣才能在**使用腳本角4 **? 我已經使用包** angularfire2 **,但它非常難以使用,並有任何簡單的方法來使用** firebase **在我的應用程序? –

1

如討論here,您可以訂閱FirebaseAuthState可觀察項並使用Firebase的updateProfile()方法。

private authState: FirebaseAuthState; 

constructor(private af: AngularFire) { 
    this.af.auth.take(1).subscribe(auth => { 
     this.authState = auth; 
} 

authState.auth.updateProfile({ 
    displayName: 'display name', 
    photoURL: 'some/url' 
}).then(() => { 
    ... 
}); 
相關問題