From 84a1d16de34412477935e1e63eaa2362bd1f47dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 14 Sep 2022 22:42:10 +0200 Subject: [PATCH] accept ?token= in server URL. --- src/component/main.vue | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/component/main.vue b/src/component/main.vue index 37809f3b..9ccb9045 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -252,6 +252,12 @@ url = location.href } + // url can contain ?token= + let token = new URL(url).searchParams.get('token') || undefined + + // get URL without query params + url = url.split('?')[0] + const httpURL = url.replace(/^ws/, 'http').replace(/\/$|\/ws\/?$/, '') this.api.setUrl(httpURL) Vue.set(this.state.connection, 'url', httpURL) @@ -264,6 +270,9 @@ Vue.set(this.state, 'authenticated', false) } + // save token to state + Vue.set(this.state.connection, 'token', token) + if (!this.autologin) return await this.authenticate() @@ -272,6 +281,10 @@ } public async authenticate(token?: string) { + if (!token) { + token = this.state.connection.token + } + if (!token && this.autologin) { token = localStorage.getItem('neko_session') ?? undefined }