我刚刚通过此https://firebase.google.com/docs/auth/admin/create-custom-tokens使用Firebase自定义身份验证系统实现了Linkedin注册和登录。
它正在工作,但在Firebase上的标识符为空。
我应该如何发送?创建用户后我应该更新它吗? 我想将其保存在创建时。
谢谢
答案 0 :(得分:1)
尝试一下: 在您的服务器上,在铸造自定义令牌之前,您可以使用电子邮件创建用户:
// Create the user with email first.
admin.auth().createUser({uid: uid, email: linkedinEmail})
.then(function(userRecord) {
// This will return custom token for that user above.
return admin.auth().createCustomToken(userRecord.uid);
})
.catch(function(error) {
// Some error.
});
另一个使用客户端代码的选项是在使用自定义令牌登录后设置电子邮件客户端:
firebase.auth().signInWithCustomToken(customToken)
.then(function(result) {
return firebase.auth().currentUser.updateEmail(linkedinEmail);
})
.catch(function(error) {
// Some error occurred.
});
答案 1 :(得分:-1)
在创建自定义令牌时会自己生成一个唯一的UID并将其保存在数据库中 就像有人尝试使用详细信息登录时,匹配数据库中的凭据并获取正确的UID并使用它创建自定义令牌。现在,借助自定义令牌,您可以登录
看看下面的代码 这是我的node.js项目中运行良好的代码
const functions = require('firebase-functions');
const admin = require('firebase-admin');
module.exports =函数.https.onRequest((req,res)=> {
//make a random and distinct uid
//and save it in database with the users credentials
//match them at the time of login
admin.auth().createCustomToken(uid)
.then(function(customToken) {
res.setHeader('Content-Type', 'application/json');
var error = false;
var result = {
"Error": error,
"CustomToken": customToken
};
res.send(JSON.stringify(result));
})
.catch(function(err) {
res.setHeader('Content-Type', 'application/json');
var error = true;
var result = {
"Error": error,
"Message": err
};
res.send(JSON.stringify(result));
});
});