Merge branch 'dev' into feature/12-user-management

This commit is contained in:
Philipp Dormann 2021-01-10 13:09:42 +01:00
commit e97c5c3b7e
5 changed files with 41 additions and 6 deletions

View File

@ -2,8 +2,20 @@
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
#### [0.1.2](https://git.odit.services/lfk/frontend/compare/0.1.2-1...0.1.2)
- Merge commit '2a37dfafa426e070aa136d171a1a01aa7f609d18' into dev [`#29`](https://git.odit.services/lfk/frontend/issues/29)
- Merge commit '5810b4ec4396ad650d90493fb48e2a8320865b42' into dev [`#4`](https://git.odit.services/lfk/frontend/issues/4)
- 🔒 added basic manual refresh every 4mins [`d92c6c0`](https://git.odit.services/lfk/frontend/commit/d92c6c0de9d6b72027b8aa27b22e3dc7b5116af1)
- dropped redundant console.log [`2a37dfa`](https://git.odit.services/lfk/frontend/commit/2a37dfafa426e070aa136d171a1a01aa7f609d18)
- 💾 save new auth data to localstorage [`2cbb431`](https://git.odit.services/lfk/frontend/commit/2cbb431acc0fe1aa333ddedb76510486a5fcf191)
- new license file version [CI SKIP] [`519ba79`](https://git.odit.services/lfk/frontend/commit/519ba79e1d5d97e2f59f769ef952a649481b55c0)
#### [0.1.2-1](https://git.odit.services/lfk/frontend/compare/0.1.2-0...0.1.2-1)
> 10 January 2021
- 🚀RELEASE v0.1.2-1 [`5810b4e`](https://git.odit.services/lfk/frontend/commit/5810b4ec4396ad650d90493fb48e2a8320865b42)
- 🧪 modified auto-changelog to commit CHANGELOG.md [`52aa996`](https://git.odit.services/lfk/frontend/commit/52aa99681bb02472e0433cb32b89dde814cd9467)
#### [0.1.2-0](https://git.odit.services/lfk/frontend/compare/0.1.1...0.1.2-0)

View File

@ -1,6 +1,6 @@
{
"name": "@odit/lfk-frontend",
"version": "0.1.2-1",
"version": "0.1.2",
"scripts": {
"i18n-order": "node order.js",
"dev": "snowpack dev",

File diff suppressed because one or more lines are too long

View File

@ -17,7 +17,7 @@
is_blocked_by_autologin = true;
OpenAPI.TOKEN = value.access_token;
const jwtinfo = JSON.parse(atob(OpenAPI.TOKEN.split(".")[1]));
store.login(value.access_token, jwtinfo);
store.login(value, jwtinfo);
Toastify({
text: $_("welcome_wavinghand"),
duration: 500,

View File

@ -1,12 +1,16 @@
import { writable } from 'svelte/store';
import { OpenAPI, AuthService } from '@odit/lfk-client-js';
import localForage from 'localforage';
export let users = writable([]);
export let tracks = writable([]);
const store = () => {
const state = {
auth: undefined,
access_token: undefined,
jwtinfo: undefined,
isLoggedIn: false
isLoggedIn: false,
refreshInterval: undefined
};
const { subscribe, set, update } = writable(state);
@ -18,17 +22,36 @@ const store = () => {
return state;
});
},
login(access_token, jwtinfo) {
refreshAuth() {
console.log('refreshing auth');
AuthService.authControllerRefresh({ token: state.auth.refresh_token }).then((auth) => {
console.log('got new auth');
OpenAPI.TOKEN = auth.access_token;
localForage.setItem('logindata', auth);
});
},
login(auth, jwtinfo) {
update((state) => {
state.access_token = access_token;
state.auth = auth;
state.access_token = auth.access_token;
state.jwtinfo = jwtinfo;
state.isLoggedIn = true;
//
state.refreshInterval = setInterval(() => {
this.refreshAuth();
// 4min
}, 4 * 60000);
//
return state;
});
},
logout() {
update((state) => {
state.isLoggedIn = false;
//
clearInterval(state.refreshInterval);
state.refreshInterval = undefined;
//
return state;
});
}