diff --git a/src/components/throbber.vue b/src/components/throbber.vue index 88bf393..cf78fdd 100644 --- a/src/components/throbber.vue +++ b/src/components/throbber.vue @@ -7,7 +7,7 @@ + + \ No newline at end of file diff --git a/src/lib/matrixHandler.js b/src/lib/matrixHandler.js index 96a4753..dcf2dd0 100644 --- a/src/lib/matrixHandler.js +++ b/src/lib/matrixHandler.js @@ -13,7 +13,8 @@ export class MatrixHandler { login(user, password, baseUrl, onError, callback = ()=>{}){ if (this.client){ console.log('there is already an active session'); return; } this.client = new matrix.createClient({ - baseUrl: baseUrl + baseUrl: baseUrl, + sessionStore: new matrix.WebStorageSessionStore(window.localStorage) }); this.client.login('m.login.password', { user: user, @@ -40,13 +41,18 @@ export class MatrixHandler { } tokenLogin(baseUrl, accessToken, userId){ if (this.client){ console.log('there is already an active session'); return; } - this.client = new matrix.createClient({baseUrl, accessToken, userId}); + this.client = new matrix.createClient({ + baseUrl, + accessToken, + userId, + sessionStore: new matrix.WebStorageSessionStore(window.localStorage) + }); this.user = userId; this.baseUrl = baseUrl; this.startSync(); } - logout(){ - this.client.stopClient(); + async logout(){ + await this.client.stopClient(); this.client = undefined; } startSync(callback = ()=>{}){ diff --git a/src/views/login.vue b/src/views/login.vue index 726b78e..d605fdb 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -1,18 +1,21 @@ @@ -20,10 +23,12 @@ import textbtn from '@/components/textbtn'; import {matrix} from '@/main.js'; import {cookieHandler} from "@/lib/cookieHandler"; +import ThrobberOverlay from "@/components/throbberOverlay"; export default { name: "login.vue", components: { + ThrobberOverlay, textbtn }, methods: { @@ -41,22 +46,38 @@ export default { this.loginError = 'username is in wrong style'; return; } + this.loading = 'logging in'; matrix.login(this.user, this.password, this.homeServer, (error) => { this.loginError = `login failed: ${error}`; }, token => { - let cookie = new cookieHandler(); - cookie.setCookie({ + this.loading = 'store token'; + this.cookie.setCookie({ baseUrl: this.homeServer, userId: this.user, accessToken: token }); - cookie.setExpire(15); - cookie.store(); + this.cookie.setExpire(15); + this.cookie.store(); + this.loading = false; this.$router.push('/rooms/'); }); }, - logout(){ - matrix.logout(); + async logout(){ + this.loading = 'logging out'; + await matrix.logout(); + this.loading = 'remove token'; + this.cookie.setCookie({ + baseUrl: undefined, + userId: undefined, + accessToken: undefined + }); + this.cookie.setExpire(0); + this.cookie.store(); + this.loading = false; + this.$forceUpdate(); + }, + showLogin(){ + return matrix.client === undefined; } }, data(){ @@ -65,14 +86,19 @@ export default { password: "", homeServer: "https://adb.sh", loginError: "", - showLogin: (matrix.client === undefined) + cookie: new cookieHandler(), + loading: false } } }