From 9853c5327ee78ea6dffed6b515710f6a01f45ab3 Mon Sep 17 00:00:00 2001 From: adb Date: Sun, 9 May 2021 16:07:40 +0200 Subject: [PATCH] debug and add localStorage --- package.json | 2 -- src/components/newMessage.vue | 6 ++--- src/lib/DataStore.js | 22 +++++++++++++++++++ .../{matrixHandler.js => MatrixHandler.js} | 3 ++- src/lib/cookieHandler.js | 10 ++++++--- src/main.js | 11 +++++----- src/views/login.vue | 14 ++++-------- 7 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 src/lib/DataStore.js rename src/lib/{matrixHandler.js => MatrixHandler.js} (95%) diff --git a/package.json b/package.json index 8706b37..5a19830 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,6 @@ "lint": "vue-cli-service lint" }, "dependencies": { - "@modular-matrix/parse-mxc": "^1.0.1", - "@vue-polkadot/vue-identicon": "^0.0.8", "core-js": "^3.6.5", "jdenticon": "^3.1.0", "matrix-js-sdk": "^9.1.0", diff --git a/src/components/newMessage.vue b/src/components/newMessage.vue index 93a8d6c..7adbd8d 100644 --- a/src/components/newMessage.vue +++ b/src/components/newMessage.vue @@ -36,7 +36,7 @@ this.store.setItem(key, obj[key])); + } +} \ No newline at end of file diff --git a/src/lib/matrixHandler.js b/src/lib/MatrixHandler.js similarity index 95% rename from src/lib/matrixHandler.js rename to src/lib/MatrixHandler.js index c277f43..afe4317 100644 --- a/src/lib/matrixHandler.js +++ b/src/lib/MatrixHandler.js @@ -48,7 +48,8 @@ export class MatrixHandler { baseUrl, accessToken, userId, - store: new matrix.MemoryStore(window.localStorage) + store: new matrix.MemoryStore(window.localStorage), + sessionStore: new matrix.WebStorageSessionStore(window.localStorage) }); this.user = userId; this.baseUrl = baseUrl; diff --git a/src/lib/cookieHandler.js b/src/lib/cookieHandler.js index fb8bf8e..72f9c23 100644 --- a/src/lib/cookieHandler.js +++ b/src/lib/cookieHandler.js @@ -8,11 +8,17 @@ export class cookieHandler { getCookies(){ return this.cookies; } - setCookie(cookies){ + setCookies(cookies){ Object.keys(cookies).forEach(key => { this.cookies[key] = cookies[key]; }) } + set(key, value){ + this.cookies[key] = value; + } + get(key){ + return this.cookies[key]; + } parseCookie(string){ let cookies = {}; string.replace(/ /g, '').split(';').forEach(cookie => { @@ -24,14 +30,12 @@ export class cookieHandler { reload(){ if (document.cookie) this.cookies = this.parseCookie(document.cookie); console.log('cookie loaded') - console.log(this.cookies); } store(){ Object.keys(this.cookies).forEach(key => { document.cookie = `${key}=${this.cookies[key]}; expires=${this.expires}; SameSite=${this.SameSite}; Secure;`; }); console.log('cookie stored'); - console.log(this.cookies); } toString(cookies = this.cookies){ let string = ''; diff --git a/src/main.js b/src/main.js index 4883dbf..d0bbe93 100644 --- a/src/main.js +++ b/src/main.js @@ -2,17 +2,18 @@ import Vue from 'vue' import VueRouter from 'vue-router' import App from './App.vue' import {router} from '@/router' -import {MatrixHandler} from './lib/matrixHandler.js' -import {cookieHandler} from './lib/cookieHandler.js'; +import {MatrixHandler} from './lib/MatrixHandler.js' +import {DataStore} from '@/lib/DataStore'; Vue.config.productionTip = false; Vue.use(VueRouter); export let matrix = new MatrixHandler(); -let cookie = new cookieHandler().getCookies(); -if (cookie && cookie.baseUrl && cookie.accessToken && cookie.userId) { - matrix.tokenLogin(cookie.baseUrl, cookie.accessToken, cookie.userId); +let store = new DataStore(); + +if (store.get('baseUrl') && store.get('accessToken') && store.get('userId')) { + matrix.tokenLogin(store.get('baseUrl'), store.get('accessToken'), store.get('userId')); } new Vue({ diff --git a/src/views/login.vue b/src/views/login.vue index 065bd7d..f386604 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -22,9 +22,9 @@