Search code examples
firebasevue.jscordova

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


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)
  }
});

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


Solution

  • 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.