【发布时间】:2020-09-16 14:40:16
【问题描述】:
概述
我正在 Quasar/Vue.js 和 Firebase 中构建一个需要对用户进行身份验证的网络应用程序。
我正在努力实现的目标
一个非常常见的功能 - 即使用户关闭浏览器/选项卡后也保持登录状态。
可能的解决方案
我知道我可以使用 localStorage 或 cookies 来设置用户身份验证状态。但是,我想允许 Firebase 身份验证为我做这件事(如果可以的话)。
我检查了这方面的文档 - https://firebase.google.com/docs/auth/web/auth-state-persistence 他们很好,除了我不知道在哪里放置提到的这段代码:
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(function() {
// New sign-in will be persisted with session persistence.
return firebase.auth().signInWithEmailAndPassword(email, password);
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
我不知道把它放在以下哪个地方:
- 与
onAuthStatechanged监听器? - 在 App.vue(根 Vue)实例中?
- 其他地方?
如果有人能帮忙,我会很高兴。谢谢。
【问题讨论】:
标签: javascript firebase vue.js firebase-authentication