Skip to content

Instantly share code, notes, and snippets.

@shawndeprey
Last active November 14, 2019 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawndeprey/84803756763811607f1f46a4d70eb3c8 to your computer and use it in GitHub Desktop.
Save shawndeprey/84803756763811607f1f46a4d70eb3c8 to your computer and use it in GitHub Desktop.
IdleVue implementation for SPA timeout article
import IdleVue from "idle-vue"
const eventsHub = new Vue()
Vue.use(IdleVue, {
eventEmitter: eventsHub,
idleTime: 900000, // 15 Minutes
})
new Vue({
// ...Your vue config will be here. Below it add:
onIdle() {
// Replace the following 2 lines to match 1) How you store your sessions in your vue app and 2) your signin/login route.
this.$store.dispatch("auth/destroyCurrentSession")
router.replace("signin")
},
onActive() {
// We're not using this function in this example, however, if you wanted a dialog to display
// before a user's session times out then you could use a shorter `idleTime` above and open
// a dialog in the `onIdle` function above.
},
}).$mount("#app")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment