Not perfect by any means, but does the job:
<template>
</template>
<script>
export default {
data() {
return {
timerCount: 45
}
},
watch: {
timerCount: {
handler(value) {
if (value > 0) {
setTimeout(() => {
this.timerCount--;
}, 45 * 1300);
}
if(value == 5) {
swal({
title: 'Your session is about to expire!',
text: 'Your session will expire in 5 minutes, you can carry on or end your session.',
icon: 'error',
buttons: {
cancel: {
text: "No, logout!",
value: null,
visible: true,
className: "",
closeModal: true,
},
confirm: {
text: "Keep me signed in.",
value: true,
visible: true,
className: "",
closeModal: true
}
}
}).then(okay => {
if(okay) {
axios.post('session');
this.timerCount = '';
this.timerCount = 45;
} else {
console.log('Logout');
axios.post('session/logout');
window.location = '/login';
}
});
}
},
immediate: true
}
}
}
</script>