82 lines
2.0 KiB
JavaScript
Executable File
82 lines
2.0 KiB
JavaScript
Executable File
import { createRouter, createWebHistory } from 'vue-router';
|
|
import store from '../store';
|
|
import authRoutes from './authRoutes';
|
|
import socialRoutes from './socialRoutes';
|
|
import settingsRoutes from './settingsRoutes';
|
|
import adminRoutes from './adminRoutes';
|
|
import falukantRoutes from './falukantRoutes';
|
|
import blogRoutes from './blogRoutes';
|
|
import minigamesRoutes from './minigamesRoutes';
|
|
import personalRoutes from './personalRoutes';
|
|
import marketingRoutes from './marketingRoutes';
|
|
import { applyRouteSeo } from '../utils/seo';
|
|
import apiClient from '../utils/axios';
|
|
|
|
const HomeView = () => import('../views/HomeView.vue');
|
|
|
|
const routes = [
|
|
{
|
|
path: '/',
|
|
name: 'Home',
|
|
component: HomeView,
|
|
meta: {
|
|
seo: {
|
|
i18nKey: 'home',
|
|
canonicalPath: '/',
|
|
},
|
|
},
|
|
},
|
|
...marketingRoutes,
|
|
...authRoutes,
|
|
...socialRoutes,
|
|
...settingsRoutes,
|
|
...adminRoutes,
|
|
...falukantRoutes,
|
|
...blogRoutes,
|
|
...minigamesRoutes,
|
|
...personalRoutes,
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
routes
|
|
});
|
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
// These are public entry pages. They must never be redirected because a
|
|
// persisted login has expired while the application is starting up.
|
|
if (to.meta?.publicLanding) {
|
|
return next();
|
|
}
|
|
|
|
if (to.matched.some(record => record.meta.requiresAuth)) {
|
|
if (!store.getters.isLoggedIn) {
|
|
return next('/');
|
|
} else if (!store.getters.user.active) {
|
|
return next('/activate');
|
|
}
|
|
}
|
|
|
|
if (to.matched.some(record => record.meta.requiresAdultArea)) {
|
|
try {
|
|
const response = await apiClient.post('/api/settings/account', { userId: store.getters.user.id });
|
|
if (!response.data?.isAdult) {
|
|
return next('/');
|
|
}
|
|
if (!response.data?.adultAccessEnabled) {
|
|
return next('/socialnetwork/erotic/access');
|
|
}
|
|
} catch (error) {
|
|
return next('/socialnetwork/erotic/access');
|
|
}
|
|
}
|
|
|
|
next();
|
|
});
|
|
|
|
router.afterEach((to) => {
|
|
applyRouteSeo(to);
|
|
});
|
|
|
|
export default router;
|