From c6b99563d93abb16ce1377e8500d6e19f7f35122 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Wed, 1 May 2024 10:19:00 +0200 Subject: [PATCH] Send a request for new credentials at regular intervals. Every five minutes, a message is sent via WebSocket to ask the server for a refreshed JWT token. --- lib/www/client/source/src/main.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/www/client/source/src/main.js b/lib/www/client/source/src/main.js index fc4527c..d796281 100644 --- a/lib/www/client/source/src/main.js +++ b/lib/www/client/source/src/main.js @@ -7,6 +7,8 @@ import vueDebounce from 'vue-debounce' import { mapMutations } from 'vuex'; import { markdown, markdownInline } from './lib/markdown'; import { geometryAsString } from './lib/utils'; +import { mapGetters } from 'vuex'; + Vue.config.productionTip = false @@ -14,7 +16,7 @@ Vue.use(vueDebounce); Vue.filter('markdown', markdown); Vue.filter('markdownInline', markdownInline); -Vue.filter('position', (str, item, opts) => +Vue.filter('position', (str, item, opts) => str .replace(/@POS(ITION)?@/g, geometryAsString(item, opts) || "(position unknown)") .replace(/@DMS@/g, geometryAsString(item, {...opts, dms:true}) || "(position unknown)") @@ -32,10 +34,16 @@ new Vue({ user: null, wsUrl: "/ws", - ws: null + ws: null, + wsCredentialsCheckInterval: 300*1000, // ms + wsCredentialsCheckTimer: null } }, + computed: { + ...mapGetters(["jwt"]) + }, + methods: { markdown (value) { @@ -85,6 +93,17 @@ new Vue({ this.setServerConnectionState(false); }); + if (this.wsCredentialsCheckTimer) { + clearInterval(this.wsCredentialsCheckTimer); + this.wsCredentialsCheckTimer = null; + } + + this.wsCredentialsCheckTimer = setInterval( () => { + this.ws.send(JSON.stringify({ + jwt: this.jwt + })); + }, this.wsCredentialsCheckInterval); + }, ...mapMutations(['setServerEvent', 'setServerConnectionState'])