From 73d57f0294020038f368f05d04d58f4f21abccaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 24 Apr 2021 21:22:36 +0200 Subject: [PATCH] add auto login for token. --- src/component/main.vue | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/component/main.vue b/src/component/main.vue index b7fae6e4..2ff7c30a 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -194,6 +194,12 @@ // check if is user logged in if (this.autologin) { + const token = localStorage.getItem('neko_session') + if (token) { + this.api.setToken(token) + this.websocket.setToken(token) + } + this.api.session.whoami().then(() => { Vue.set(this.state.connection, 'authenticated', true) this.websocket.connect() @@ -210,6 +216,10 @@ if (res.data.token) { this.api.setToken(res.data.token) this.websocket.setToken(res.data.token) + + if (this.autologin) { + localStorage.setItem('neko_session', res.data.token) + } } Vue.set(this.state.connection, 'authenticated', true) @@ -231,6 +241,10 @@ this.api.setToken('') this.websocket.setToken('') + if (this.autologin) { + localStorage.removeItem('neko_session') + } + Vue.set(this.state.connection, 'authenticated', false) } }