Files
memberApp/src/boot/restore-route.js
Adrian Zürcher bdcceb53e0 change whole backend and tables for gorm table references
simplify tables with table components close #31
2025-11-29 15:59:18 +01:00

44 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { boot } from 'quasar/wrappers';
import { useUserStore } from 'src/vueLib/login/userStore';
import { appApi } from './axios';
import { getLocalLastRoute, setLocalLastRoute } from 'src/localstorage/localStorage';
export default boot(async ({ router }) => {
const userStore = useUserStore();
// load user
try {
const { data } = await appApi.get('/login/me');
data.role.role = data.role;
await userStore.setUser(data);
} catch {
/* ignore error */
}
// Restore logic after router is ready but before navigation
router.isReady().then(() => {
const lastRoute = getLocalLastRoute();
const currentPath = router.currentRoute.value.fullPath;
// Restore only if:
// - were on root ("/" or "/#/"), and
// - a last route exists, and
// - the user is authenticated
if (
lastRoute &&
['/', '/#/', '/#/index.html'].includes(currentPath) &&
userStore.isAuthenticated
) {
router.replace(lastRoute).catch(() => {});
}
});
// Save the route after every successful navigation
router.afterEach((to) => {
// Don't save login page as "last route"
if (to.path !== '/login' && to.path !== '/') {
setLocalLastRoute(to.fullPath);
}
});
});