This commit is contained in:
2025-06-05 20:00:58 +03:00
parent c8f3c9801f
commit 1c732e16dd
203 changed files with 9793 additions and 3960 deletions

View File

@@ -6,18 +6,8 @@ import {
createWebHistory,
} from 'vue-router'
import routes from './routes'
import { useAuthStore } from 'stores/auth'
import { useProjectsStore } from 'stores/projects'
/*
* If not building with SSR mode, you can
* directly export the Router instantiation;
*
* The function below can be async too; either use
* async/await or return a Promise which resolves
* with the Router instance.
*/
export default defineRouter(function (/* { store, ssrContext } */) {
const createHistory = process.env.SERVER
? createMemoryHistory
@@ -32,30 +22,28 @@ export default defineRouter(function (/* { store, ssrContext } */) {
// quasar.conf.js -> build -> publicPath
history: createHistory(process.env.VUE_ROUTER_BASE),
})
const publicPaths = ['/login', '/create-account', '/recovery-password']
Router.beforeEach(async (to) => {
const authStore = useAuthStore()
console.log(to)
if (to.name === 'settings') return;
const projectsStore = useProjectsStore()
// Инициализация хранилища перед проверкой
if (!authStore.isInitialized) {
await authStore.initialize()
}
// Проверка авторизации для непубличных маршрутов
if (!publicPaths.includes(to.path)) {
if (!authStore.isAuthenticated) {
return {
path: '/login',
query: { redirect: to.fullPath }
}
if (to.params.id) {
const projectId = Number(to.params.id)
if (!projectsStore.isInit) await projectsStore.init()
const project = projectsStore.projectById(projectId)
if (!project) return { name: 'page404' }
if (projectsStore.currentProjectId !== projectId) {
projectsStore.setCurrentProjectId(projectId)
}
}
// Редирект авторизованных пользователей с публичных маршрутов
if (publicPaths.includes(to.path) && authStore.isAuthenticated) {
return { path: '/' }
} else {
if (!projectsStore.startProjectId) return { name: 'page404' }
projectsStore.setCurrentProjectId(projectsStore.startProjectId)
return { name: 'files', params: { id: projectsStore.startProjectId }}
}
})
@@ -67,11 +55,10 @@ export default defineRouter(function (/* { store, ssrContext } */) {
if (window.history.length > 1) {
Router.go(-1)
} else {
await Router.push('/projects')
await Router.push({ name: 'main'})
}
}
}
Router.afterEach((to) => {
const BackButton = window.Telegram?.WebApp?.BackButton;
@@ -87,11 +74,6 @@ export default defineRouter(function (/* { store, ssrContext } */) {
BackButton.offClick(handleBackButton as () => void)
BackButton.onClick(handleBackButton as () => void)
}
if (!to.params.id) {
const projectsStore = useProjectsStore()
projectsStore.setCurrentProjectId(null)
}
})
return Router