Compare commits

..

1 Commits

Author SHA1 Message Date
Ferdinand Thiessen 29c085bd2c [core] Save baseURL into PersistentStorage 2021-11-26 20:55:45 +01:00
3 changed files with 7 additions and 7 deletions

View File

@ -10,7 +10,7 @@ function loadToken() {
} }
function clearToken() { function clearToken() {
PersistentStorage.remove('fg_token'); void PersistentStorage.remove('fg_token');
} }
export function saveToken(token?: string) { export function saveToken(token?: string) {

View File

@ -1,7 +1,8 @@
import { LocalStorage, Platform } from 'quasar'; import { LocalStorage, Platform } from 'quasar';
import { Storage } from '@capacitor/storage'; import { Storage } from '@capacitor/storage';
type GetReturn = Date | number | boolean | string | object; // eslint-disable-next-line @typescript-eslint/no-explicit-any
type PersitentTypes = Date | RegExp | number | boolean | string | object;
export class PersistentStorage { export class PersistentStorage {
static clear() { static clear() {
@ -14,13 +15,12 @@ export class PersistentStorage {
else return Promise.resolve(LocalStorage.remove(key)); else return Promise.resolve(LocalStorage.remove(key));
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any static set(key: string, value: PersitentTypes) {
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 GetReturn>(key: string) { static get<T extends PersitentTypes>(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)

View File

@ -25,13 +25,13 @@ export default defineComponent({
setup() { setup() {
const router = useRouter(); const router = useRouter();
const server = ref<string | undefined>(api.defaults.baseURL); const server = ref(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');
router.push({ name: 'login' }).then(() => router.go(0)); void router.push({ name: 'login' }).then(() => router.go(0));
}); });
} }
} }