ionic firebase 从实时数据库获取用户信息
ionic firebase get user information from real time database
我试图在我的 Firebase 数据库中获取用户信息(例如:用户名),但在 .ts
文件中,我不知道如何编码
我厌倦了使用 auth.uid
从数据库中获取用户名,但没有成功。下面是我用来保存用户配置文件的代码。效果很好。
this.afAuth.authState.pipe(take(1)).subscribe(auth => {
let path= 'userProfile'+'/'+ auth.uid;
this.afDatabase.object(path).set(this.profile);
})
但我不知道如何获取它的信息。所以在我的数据库中,"userProfile" 下有 "username"。我如何使用此逻辑来获取用户名?我需要使用 auth.uid
在我的应用程序中显示用户名
您似乎有以下数据库:
userProfile
userid
username : peter
您可以执行以下操作:
export class DataComponent implements OnInit{
ref : any;
constructor(db: AngularFireDatabase, public afAuth: AngularFireAuth) {
ref = db.list('/userProfile', ref => ref.orderByKey().equalTo(this.afAuth.auth.currentUser.uid)).valueChanges();
}
ngOnInit(){
ref.subscribe(items => {
console.log(items);
});
}
}
在这里您查询节点 userId
然后使用该节点您可以检索 username
.
检查以下内容:
https://github.com/angular/angularfire2/blob/master/docs/rtdb/querying-lists.md
我试图在我的 Firebase 数据库中获取用户信息(例如:用户名),但在 .ts
文件中,我不知道如何编码
我厌倦了使用 auth.uid
从数据库中获取用户名,但没有成功。下面是我用来保存用户配置文件的代码。效果很好。
this.afAuth.authState.pipe(take(1)).subscribe(auth => {
let path= 'userProfile'+'/'+ auth.uid;
this.afDatabase.object(path).set(this.profile);
})
但我不知道如何获取它的信息。所以在我的数据库中,"userProfile" 下有 "username"。我如何使用此逻辑来获取用户名?我需要使用 auth.uid
在我的应用程序中显示用户名
您似乎有以下数据库:
userProfile
userid
username : peter
您可以执行以下操作:
export class DataComponent implements OnInit{
ref : any;
constructor(db: AngularFireDatabase, public afAuth: AngularFireAuth) {
ref = db.list('/userProfile', ref => ref.orderByKey().equalTo(this.afAuth.auth.currentUser.uid)).valueChanges();
}
ngOnInit(){
ref.subscribe(items => {
console.log(items);
});
}
}
在这里您查询节点 userId
然后使用该节点您可以检索 username
.
检查以下内容:
https://github.com/angular/angularfire2/blob/master/docs/rtdb/querying-lists.md