- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为使用 Firebase 的网络应用程序创建“记住我”功能。
我的目标是,当用户点击“记住我”并成功登录时,他们的身份验证 token 将使用 localStorage 存储,并且他们会在下次访问时自动登录(为了安全起见,我更喜欢将其原始凭据存储在 localStorage 中目的)。
但是,当我尝试调用 firebase.auth().createCustomToken
时,我收到一条错误消息,提示它不存在。这是错误的方法还是错误的 firebase 函数调用?谢谢!
这是我的代码示例:
var customToken = firebase.auth().createCustomToken(user.uid);
localStorage.setItem("savedToken", customToken);
然后我打算使用这条线重新登录:
firebase.auth().signInWithCustomToken(localStorage.getItem("savedToken")).then(function() {
最佳答案
firebase.auth().createCustomToken
仅在服务器 API 中可用。
要使用电子邮件和密码进行身份验证并获取 session token ,请尝试以下操作:
firebase.auth().signInWithEmailAndPassword(email, password)
.then(function(user) {
user.getToken().then(function(token) {
localStorage.setItem("savedToken", token); // store the token
});
})
.catch(function(error) {
// handle error...
});
这也适用于其他身份验证方法;只需使用 User.getToken
.稍后,如果您有一个 token (仍在客户端上),并且您想要使用它进行身份验证,只需执行您当前正在执行的操作即可:
var token = localStorage.getItem("savedToken"); // get stored token
firebase.auth().signInWithCustomToken(token).catch(function(error) {
// handle error...
});
以上代码不起作用,因为 signInWithCustomToken
仅适用于您的服务器使用 createCustomToken
生成的 token 。我不确定如何使用电子邮件/密码 token 进行身份验证。
关于javascript - firebase.auth().createCustomToken 在网络应用程序上未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39197279/
结合使用新的 Firebase Cloud Functions 和管理 SDK。 我想使用 admin.auth().createCustomToken() 函数。调用此函数会产生错误消息 Error
我正在尝试为使用 Firebase 的网络应用程序创建“记住我”功能。 我的目标是,当用户点击“记住我”并成功登录时,他们的身份验证 token 将使用 localStorage 存储,并且他们会在下
我正在实现“使用自定义 token 登录”。我在 Firebase documentation 中找到了这段代码. firebaseAuth.createCustomToken(uid)
我通过 createCustomToken() 创建了自定义身份验证 token ,请参阅 https://firebase.google.com/docs/auth/admin/create-cus
我正在尝试将我的自定义身份验证代码从 firebase-queue worker 移动到 firebase 函数。当我尝试调用 createCustomToken 方法时出现以下错误。 下面是我用来创
我是一名优秀的程序员,十分优秀!