[Vuejs]-Call Auth.currentSession() At 5 minute intervals in Vuex Store

1👍

My solution was to create an action in the store.js file that calls Auth.currentsession, and in the App.vue file dispatch the refreshSession event every 9 minutes.

store.js

import { createStore } from 'vuex'
import { Auth } from 'aws-amplify'


export default createStore({
  state: {
    session: null
  },
  getters: {

  },
  mutations: {
    setSession(state, value){
      state.session = value
    }
  },

  actions: {
    async refreshSession({ commit }){
      const session = await Auth.currentSession()
      commit('setSession', session)
    }
  },
  modules: {

  }
})

App.vue


  created(){
      this.sessionInterval = setInterval(() => {
        this.$store.dispatch('refreshSession');
      }, 540000);
  },

Leave a comment