diff --git a/src/boot/axios.ts b/src/boot/axios.ts index c8cd602..403ea59 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -1,5 +1,4 @@ import { useMainStore, api } from '@flaschengeist/api'; -import { LocalStorage, Notify } from 'quasar'; import { AxiosError } from 'axios'; import { boot } from 'quasar/wrappers'; import config from 'src/config'; @@ -31,7 +30,8 @@ function minify(o: unknown, cloned = false) { } export default boot(({ router }) => { - api.defaults.baseURL = LocalStorage.getItem('baseURL') || config.baseURL; + // Persisted value is read in plugins.ts boot file! + api.defaults.baseURL = config.baseURL; /*** * Intercept requests @@ -95,17 +95,3 @@ export default boot(({ router }) => { }); export { api }; - -export const setBaseURL = (url: string) => { - LocalStorage.set('baseURL', url); - api.defaults.baseURL = url; - Notify.create({ - message: 'Serveraddresse gespeichert', - position: 'bottom', - caption: `${url}`, - color: 'positive', - }); - setTimeout(() => { - window.location.reload(); - }, 5000); -}; diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index a3e6ba7..ab7f195 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -1,10 +1,10 @@ -import { Notify } from 'quasar'; +import { Notify, Platform } from 'quasar'; import { api } from 'src/boot/axios'; import { boot } from 'quasar/wrappers'; import routes from 'src/router/routes'; -import { AxiosResponse } from 'axios'; import { RouteRecordRaw } from 'vue-router'; import { FG_Plugin } from '@flaschengeist/types'; +import { PersistentStorage } from '@flaschengeist/api'; /**************************************************** ******** Internal area for some magic ************** @@ -264,16 +264,24 @@ function loadPlugin( return true; } +async function loadBaseUrl() { + return PersistentStorage.get('baseURL').then((url) => { + if (url !== null) api.defaults.baseURL = url; + console.log('loaded: ', url, api.defaults.baseURL); + }); +} /** * Loading backend information * @returns Backend object or null */ async function getBackend() { try { - const { data }: AxiosResponse = await api.get('/'); + const { data } = await api.get('/'); + if (!data || typeof data !== 'object' || !('plugins' in data)) + throw Error('Invalid backend response received'); return data; } catch (e) { - console.warn(e); + console.error('Loading backend', e); return null; } } @@ -282,10 +290,13 @@ async function getBackend() { * Boot file, load all required plugins, check for dependencies */ export default boot(async ({ router, app }) => { + await loadBaseUrl(); const backend = await getBackend(); - if (!backend || typeof backend !== 'object' || !('plugins' in backend)) { - console.log('Backend error'); - router.isReady().finally(() => void router.push({ name: 'offline', params: { refresh: 1 } })); + if (backend === null) { + router.isReady().finally(() => { + if (Platform.is.capacitor) void router.push({ name: 'setup_backend' }); + else void router.push({ name: 'offline', params: { refresh: 1 } }); + }); return; } diff --git a/src/pages/Backend.vue b/src/pages/Backend.vue new file mode 100644 index 0000000..2f5b1ef --- /dev/null +++ b/src/pages/Backend.vue @@ -0,0 +1,46 @@ + + + diff --git a/src/pages/Login.vue b/src/pages/Login.vue index 6cb7614..7d99aa2 100644 --- a/src/pages/Login.vue +++ b/src/pages/Login.vue @@ -44,25 +44,13 @@
- -
- - - -
Servereinstellung
- - -
-
-
-
@@ -73,34 +61,20 @@ import { Loading, Notify } from 'quasar'; import { notEmpty, useMainStore, useUserStore } from '@flaschengeist/api'; import { PasswordInput } from '@flaschengeist/api/components'; import { defineComponent, ref } from 'vue'; -import { setBaseURL, api } from 'boot/axios'; -import { useQuasar } from 'quasar'; export default defineComponent({ name: 'PageLogin', components: { PasswordInput }, setup() { + const mainRoute = { name: 'dashboard' }; + const mainStore = useMainStore(); const userStore = useUserStore(); - const mainRoute = { name: 'dashboard' }; const router = useRouter(); /* Stuff for the real login page */ const userid = ref(''); const password = ref(''); - const server = ref(api.defaults.baseURL); - const visible = ref(false); - const quasar = useQuasar(); - - function openServerSettings() { - visible.value = !visible.value; - } - - function changeUrl() { - if (server.value) { - setBaseURL(server.value); - } - } async function doLogin() { Loading.show({ message: 'Du wirst angemeldet' }); @@ -155,16 +129,11 @@ export default defineComponent({ } return { - changeUrl, doLogin, doReset, notEmpty, - openServerSettings, password, - server, userid, - visible, - quasar, }; }, }); diff --git a/src/router/routes.ts b/src/router/routes.ts index b7a0cd6..d258554 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -53,6 +53,11 @@ const routes: RouteRecordRaw[] = [ name: 'offline', component: () => import('pages/Offline.vue'), }, + { + path: '/setup-backend', + name: 'setup_backend', + component: () => import('pages/Backend.vue'), + }, // Always leave this as last one, // but you can also remove it {