2017-10-29 31 views
0

私はウェブサイトを構築しています。最新のfirebaseスクリプトとすべてを使用しています。 作成したカスタムユーザー属性を要求すると、「未定義」と表示されます。firebase認証のカスタム属性のエラー

CustomAttributes:
ポイント
ownedavatars

コード:あなたは、任意のCを保存するためにupdateProfileを使用することはできません

新規アカウント

var user = firebase.auth().currentUser; 
user.updateProfile({ 
    displayName: //username, 
    photoURL: //icon, 
    points: 0, 
    ownedavatars: "default" 
}).then(function() { 
    user.sendEmailVerification().then(function() { 
    //it would save email and password and then redirect here 
    }).catch(function(error) { 
    console.log(error.message); 
    }); 
}).catch(function(error) { 
    console.log(error.message); 
}); 

ログイン

var listofavatars; 
firebase.auth().signInWithEmailAndPassword(email, password).then(function() { 
    var user = firebase.auth().currentUser; 
    if (user != null) { 
    document.getElementById("user").innerHTML = user.displayName; 
    if (user.points == undefined) { 
     document.getElementById("points").innerHTML = "0p"; 
    } else { 
     document.getElementById("points").innerHTML = user.points + "p"; 
    } 
    listofavatars = user.ownedavatars; 
    if (user.photoURL == "default") { 
     document.getElementById("avatar").src = //would pull default; 
    } else { 
     document.getElementById("avatar").src = //would pull any other icon saved; 
    } 
    } 
}).catch(function(error) { 
    alert(error.message + " Code:" + error.code); 
}); 

答えて

0

カスタムユーザ変数。このAPIは現在photoURLとdisplayName`をサポートしています。他のユーザーデータを保存するには、別のデータベースを使用する必要があります。 FirebaseリアルタイムデータベースまたはFirestoreを使用して、そのようにすることができます。あなたは役割ベースのアクセス制御のためのユーザー固有のデータを保存する必要がある場合はhttps://firebase.google.com/docs/database/security/user-security

、カスタムユーザーを設定するFirebase管理SDKを使用することができます属性:ここで安全にユーザー固有のデータを保存する方法の例です https://firebase.google.com/docs/auth/admin/custom-claims

ただし、このカスタムユーザーデータをアクセス制御に使用することを強くお勧めします。その他のデータについては、上記の専用データベースを使用してください。

関連する問題