我正在尝试使用 Framework-7 Vuejs 创建一个应用程序.即使在使用 Firebase 退出应用程序后,我也想让我的用户保持登录状态 [英] I'm trying to create an app using Framework-7 Vuejs. I want to make my user stay logged in even after exiting the app using Firebase

查看:29
本文介绍了我正在尝试使用 Framework-7 Vuejs 创建一个应用程序.即使在使用 Firebase 退出应用程序后,我也想让我的用户保持登录状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加 Firebase 的代码我的 Framework-7 Vue.js 应用程序.这样用户甚至可以在退出应用程序后保持登录状态.

I want to add Firebase's code in my Framework-7 Vue.js app. So that a user can stay logged in even arter exiting the app.

    firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    store.commit(setSignedIn, true)
  } else {
    store.commit(setSignedIn, false)
  }
});

我需要在我的项目的 app.js 中添加这个:

I need to add this in my app.js of my project:

// Import Vue
import { createApp } from 'vue';

// Import Framework7
import Framework7 from 'framework7/lite-bundle';

// Import Framework7-Vue Plugin
import Framework7Vue, { registerComponents } from 'framework7-vue/bundle';

// Import Framework7 Styles
import 'framework7/framework7-bundle.css';

// Import Icons and App Custom Styles
import '../css/icons.css';
import '../css/app.css';

// Import App Component
import App from '../components/app.vue';
import store from '../pages/store/store';

// Init Framework7-Vue Plugin
Framework7.use(Framework7Vue);

// Init App
const app = createApp(App);

app.use(store)

// Register Framework7 Vue components
registerComponents(app);

// Mount the app
app.mount('#app');

有人可以帮我做这件事吗?谢谢

Can someone please help me to do this. Thanks

推荐答案

我正在使用 Vuex Persisted声明 包用于此类目的.添加非常简单.试试看.使用 Vuex Persisted State,您的 Vuex 存储将存储在 localStorage 中,因此用户在退出应用程序后不会被注销.

I am using Vuex Persisted State package for such purposes. It is quite simple to add. Try it out. With Vuex Persisted State your Vuex store will be stored in localStorage so the user won't be logged out after exiting the app.

这篇关于我正在尝试使用 Framework-7 Vuejs 创建一个应用程序.即使在使用 Firebase 退出应用程序后,我也想让我的用户保持登录状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆