Compare commits

..

No commits in common. "88f36575fb81c47b2e88f708890da77dcadde2e1" and "e5535f18692d7afc3f2636283722e61aa0437c59" have entirely different histories.

3 changed files with 0 additions and 100 deletions

View File

@ -39,7 +39,6 @@
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@odit/lfk-client-js": "^1.0.1",
"bwip-js": "3.4.0" "bwip-js": "3.4.0"
}, },
"release-it": { "release-it": {

7
pnpm-lock.yaml generated
View File

@ -1,9 +1,6 @@
lockfileVersion: '6.0' lockfileVersion: '6.0'
dependencies: dependencies:
'@odit/lfk-client-js':
specifier: ^1.0.1
version: 1.0.1
bwip-js: bwip-js:
specifier: 3.4.0 specifier: 3.4.0
version: 3.4.0 version: 3.4.0
@ -495,10 +492,6 @@ packages:
'@octokit/openapi-types': 16.0.0 '@octokit/openapi-types': 16.0.0
dev: true dev: true
/@odit/lfk-client-js@1.0.1:
resolution: {integrity: sha512-eGwUW1MIh7sCzlLNRBLuBvLGGCHoOzmHovHnPqpMDn+fziIIX+fcmt40mdISucZwJDJqnOff4+eHimsHfSQO8A==}
dev: false
/@odit/license-exporter@0.0.12: /@odit/license-exporter@0.0.12:
resolution: {integrity: sha512-k5KxyTOk3Qz/OzId5VNXKjYOz1C4cMVfRHbq3X0VS4BM2rRuIgabrg/lbmZXDM1ExJkdBXi9sqiQ4h7N5bVbLQ==} resolution: {integrity: sha512-k5KxyTOk3Qz/OzId5VNXKjYOz1C4cMVfRHbq3X0VS4BM2rRuIgabrg/lbmZXDM1ExJkdBXi9sqiQ4h7N5bVbLQ==}
hasBin: true hasBin: true

View File

@ -1,92 +0,0 @@
import { AuthService, OpenAPI, type ResponseAuth } from '@odit/lfk-client-js';
import { writable } from 'svelte/store';
type UserState = {
access_token: string;
refresh_token: string;
isLoggedIn: boolean;
refreshInterval: number
};
const userStore = () => {
const state: UserState = {
access_token: '',
refresh_token: '',
isLoggedIn: false,
refreshInterval: 0
};
const { subscribe, set, update } = writable(state);
const methods = {
async login(resAuth: ResponseAuth) {
update((state: UserState) => {
if (!resAuth) {
return state;
}
state.access_token = resAuth.access_token;
state.refresh_token = resAuth.refresh_token;
state.isLoggedIn = true;
state.refreshInterval = setInterval(() => {
this.refreshAuth();
}, 2 * 60000)
localStorage.setItem('userdata', JSON.stringify(state));
localStorage.setItem('access_token', state.access_token);
localStorage.setItem('refresh_token', state.refresh_token);
return state;
});
},
async refreshAuth() {
try {
const authRes = await AuthService.authControllerRefresh({ token: state.refresh_token }) as ResponseAuth;
OpenAPI.TOKEN = authRes.access_token;
} catch {
this.logout();
}
},
loginFromStorage() {
console.log('loginFromStorage');
const access_token = localStorage.getItem('token');
if (!access_token) {
throw new Error('Unauthorized');
}
const storagedata = localStorage.getItem('userdata');
const userdata = JSON.parse(storagedata || '{}') as UserState;
update((state: UserState) => {
state.access_token = access_token;
state.refresh_token = userdata.refresh_token;
state.isLoggedIn = true;
state.refreshInterval = setInterval(() => {
this.refreshAuth();
}, 2 * 60000);
return state;
});
this.refreshAuth
},
async logout() {
update((state: UserState) => {
state.isLoggedIn = false;
state.access_token = '';
state.refresh_token = '';
state.refreshInterval = 0;
localStorage.clear();
return state;
});
}
};
return {
subscribe,
set,
update,
state,
...methods
};
};
export default userStore();