0

firebaseのデータを更新/追加しようとしています。私はFacebookのログインを使いました。私は新しいデータのキーとしてUserIDを使用したいと思います。#ionicベースのデータキーを変更する

(以下ピクトを確認してください)

私はそれを使用したいユーザーID:

The userID that i want to use it

私は、ユーザーIDとそのキーを置き換えたい:

i want to replace that key with the userID

fblogin(){ 
this.facebook.login(['email']) 
.then(res=> { 
const fc = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken); 
firebase.auth().signInWithCredential(fc) 
    .then(fs => { 

    this.facebook.api('me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)', []).then(profile => { 
    this.newuser = {name: profile['first_name'] ,email: profile['email'],picture: profile['picture_large']['data']['url'],phone:''} 
    this.navCtrl.push(HomePage); 
    console.log(fs.uid); 
    this.db.list('/users/'+ fs.uid).update(this.newuser); 
    }); 

このエラーが発生しましたコンパイル:

供給この行で呼び出し対象

の署名をmatchanyないパラメータ:this.db.list('/users/'+ fs.uid).update(this.newuser);

任意のヘルプ?

答えて

0

FBエラーが正しいように見えます。ユーザーが独自のFB id

と一緒に保存されているように、あなたは、データベース内usersレコードを作成したコードは表示されませんが、ときに私はあなたがやりたいと思うことは設定し、オブジェクトされてuidに更新カント最初にusersレコードを保存します。しかし、uidが返却される前にuserが保存されている可能性があるため、これが問題になる可能性があります。私はあなたのコードスニペットで話すことができません。それにもかかわらず、登録時にusers/レコードが作成されていればうまくいくと思うコードを書きます。

サービス

async signupUser(email: string, password: string) { 
    try { 
    const result = await this.afA.auth.createUserWithEmailAndPassword(email, password); 
    return result; 
    } catch (err) { 
    console.log('error', err); 
    } 
} 

だから、これは最初にここで重要なのユーザーがFB uidが作成されたとコンポーネント

this.authData.signupUser(email,password).then(userData => { 
    console.log(userData) // <- this is result 
} 
返さ result

で開催されていることで、Facebookのせずにユーザーを作成します

次に、uidが返されたFBでレコードを作成します。

this.db.object(`users/${userData.uid}/`).set(data); 

.set(data)は、users/uid名前空間に保存するデータです。

基本的に、ユーザーが最初に登録するときに、uid名前空間を持つユーザーテーブルを作成する必要があります。その後、uidでユーザーを更新することができます(電子メールは、すべてのユーザーに対して一意である必要があるため)、電子メールに基づいてユーザをfindしてから更新でき、あなたの現在のコードでfs.uid


のFacebookから返されました。.. 。

this.db.object('/users/'+ fs.uid).update(this.newuser); 

の代わりに::lodashと

はそれだけで

let foundUser = find(this.db.list('users'),{ 'email' : fs.email } 

// and then update based on the object key 

this.db.list('/users/'+ Object.keys(foundUser)).update(this.newuser); 
0

私が使用して問題を修正している

this.db.list('/users/'+ fs.uid).update(this.newuser); 

そして、それは正常に動作します! ありがとうございました。

関連する問題