Met*_*bak 7 firebase firebase-authentication
我刚刚通过这个https://firebase.google.com/docs/auth/admin/create-custom-tokens使用 firebase 自定义身份验证系统实现了linkedin 注册和登录
它正在工作,但 firebase 上的标识符为空。
我应该怎么寄?创建用户后我应该更新它吗?我想在创建时保存它。
谢谢
试试这个:在您的服务器上,在创建自定义令牌之前,您可以使用电子邮件创建用户:
// 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.
});
Run Code Online (Sandbox Code Playgroud)
使用客户端代码的另一个选项是在使用自定义令牌登录后设置电子邮件客户端:
firebase.auth().signInWithCustomToken(customToken)
.then(function(result) {
return firebase.auth().currentUser.updateEmail(linkedinEmail);
})
.catch(function(error) {
// Some error occurred.
});
Run Code Online (Sandbox Code Playgroud)
Har*_*Kal -1
创建自定义令牌时,您自己生成一个唯一的 UID 并将其保存在数据库中,当有人尝试使用与数据库中的凭据匹配的详细信息登录时,获取正确的 UID 并使用它创建自定义令牌。现在借助自定义令牌您可以登录
看看下面的代码,这是我的 node.js 项目中运行良好的代码
const functions = require('firebase-functions');
Run Code Online (Sandbox Code Playgroud)
const admin = require('firebase-admin');
module.exports = functions.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));
});
Run Code Online (Sandbox Code Playgroud)
});
| 归档时间: |
|
| 查看次数: |
2211 次 |
| 最近记录: |