From 594a828358e738242d8bf1deee25964f0b40710d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 10 Dec 2022 12:51:28 +0100 Subject: [PATCH] Expire login info - request re-login. closes #1015 --- src/components/BotEntry.vue | 18 ++++++++++--- src/components/BotList.vue | 26 +++++++++++++++--- src/components/Login.vue | 54 ++++++++++++++++++++++++++++--------- src/shared/userService.ts | 24 +++++++++++++++-- src/stores/ftbot.ts | 3 +++ src/types/auth.ts | 4 +++ src/views/LoginModal.vue | 23 +++++++++++++--- 7 files changed, 126 insertions(+), 26 deletions(-) diff --git a/src/components/BotEntry.vue b/src/components/BotEntry.vue index 7ab673be..02b9b4db 100644 --- a/src/components/BotEntry.vue +++ b/src/components/BotEntry.vue @@ -21,14 +21,22 @@
- + - + + + @@ -48,6 +56,7 @@ diff --git a/src/shared/userService.ts b/src/shared/userService.ts index e10dceda..f2178450 100644 --- a/src/shared/userService.ts +++ b/src/shared/userService.ts @@ -66,7 +66,7 @@ export class UserService { * Retrieve Login info object for the given bot * @returns Login Info object */ - private getLoginInfo(): AuthStorage { + public getLoginInfo(): AuthStorage { const info = UserService.getAllLoginInfos(); if (this.botId in info && 'apiUrl' in info[this.botId] && 'refreshToken' in info[this.botId]) { return info[this.botId]; @@ -74,6 +74,7 @@ export class UserService { return { botName: '', apiUrl: '', + username: '', refreshToken: '', accessToken: '', autoRefresh: false, @@ -131,7 +132,7 @@ export class UserService { this.removeLoginInfo(); } - public async login(auth: AuthPayload) { + private async loginCall(auth: AuthPayload): Promise { // Login using username / password const { data } = await axios.post<{}, AxiosResponse>( `${auth.url}/api/v1/token/login`, @@ -149,7 +150,26 @@ export class UserService { refreshToken: data.refresh_token || '', autoRefresh: true, }; + return Promise.resolve(obj); + } + return Promise.reject('login failed'); + } + + public async refreshLogin(auth: AuthPayload) { + try { + const obj = await this.loginCall(auth); this.storeLoginInfo(obj); + } catch (e) { + console.error(e); + } + } + + public async login(auth: AuthPayload) { + try { + const obj = await this.loginCall(auth); + this.storeLoginInfo(obj); + } catch (e) { + console.error(e); } } diff --git a/src/stores/ftbot.ts b/src/stores/ftbot.ts index 0ab22826..e40190e9 100644 --- a/src/stores/ftbot.ts +++ b/src/stores/ftbot.ts @@ -183,6 +183,9 @@ export function createBotSubStore(botId: string, botName: string) { logout() { userService.logout(); }, + getLoginInfo() { + return userService.getLoginInfo(); + }, rename(name: string) { userService.renameBot(name); }, diff --git a/src/types/auth.ts b/src/types/auth.ts index 8821377a..1954f1a3 100644 --- a/src/types/auth.ts +++ b/src/types/auth.ts @@ -24,6 +24,10 @@ export interface AuthStorage { autoRefresh: boolean; } +export interface AuthStorageWithBotId extends AuthStorage { + botId: string; +} + /** Auth Storage container */ export interface AuthStorageMulti { [key: string]: AuthStorage; diff --git a/src/views/LoginModal.vue b/src/views/LoginModal.vue index 64e8928d..3d723ca7 100644 --- a/src/views/LoginModal.vue +++ b/src/views/LoginModal.vue @@ -1,26 +1,31 @@