Compare commits
1 Commits
29c085bd2c
...
14a81f6fdf
Author | SHA1 | Date |
---|---|---|
Ferdinand Thiessen | 14a81f6fdf |
|
@ -10,7 +10,7 @@ function loadToken() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearToken() {
|
function clearToken() {
|
||||||
void PersistentStorage.remove('fg_token');
|
PersistentStorage.remove('fg_token');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveToken(token?: string) {
|
export function saveToken(token?: string) {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { LocalStorage, Platform } from 'quasar';
|
import { LocalStorage, Platform } from 'quasar';
|
||||||
import { Storage } from '@capacitor/storage';
|
import { Storage } from '@capacitor/storage';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
type GetReturn = Date | number | boolean | string | object;
|
||||||
type PersitentTypes = Date | RegExp | number | boolean | string | object;
|
|
||||||
|
|
||||||
export class PersistentStorage {
|
export class PersistentStorage {
|
||||||
static clear() {
|
static clear() {
|
||||||
|
@ -15,12 +14,13 @@ export class PersistentStorage {
|
||||||
else return Promise.resolve(LocalStorage.remove(key));
|
else return Promise.resolve(LocalStorage.remove(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
static set(key: string, value: PersitentTypes) {
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
static set(key: string, value: any) {
|
||||||
if (Platform.is.capacitor) return Storage.set({ key, value: JSON.stringify(value) });
|
if (Platform.is.capacitor) return Storage.set({ key, value: JSON.stringify(value) });
|
||||||
else return Promise.resolve(LocalStorage.set(key, value));
|
else return Promise.resolve(LocalStorage.set(key, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
static get<T extends PersitentTypes>(key: string) {
|
static get<T extends GetReturn>(key: string) {
|
||||||
if (Platform.is.capacitor)
|
if (Platform.is.capacitor)
|
||||||
return Storage.get({ key }).then((v) =>
|
return Storage.get({ key }).then((v) =>
|
||||||
v.value === null ? null : (JSON.parse(v.value) as T)
|
v.value === null ? null : (JSON.parse(v.value) as T)
|
||||||
|
|
|
@ -25,13 +25,13 @@ export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const server = ref(api.defaults.baseURL);
|
const server = ref<string | undefined>(api.defaults.baseURL);
|
||||||
|
|
||||||
function changeUrl() {
|
function changeUrl() {
|
||||||
if (server.value) {
|
if (server.value) {
|
||||||
void PersistentStorage.set('baseURL', server.value).then(() => {
|
void PersistentStorage.set('baseURL', server.value).then(() => {
|
||||||
console.log('uiuiui');
|
console.log('uiuiui');
|
||||||
void router.push({ name: 'login' }).then(() => router.go(0));
|
router.push({ name: 'login' }).then(() => router.go(0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue