Merge commit '2a37dfafa426e070aa136d171a1a01aa7f609d18' into dev
close #29
This commit is contained in:
commit
4af3cd158d
@ -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,
|
||||
|
29
src/store.js
29
src/store.js
@ -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;
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user