This commit is contained in:
2025-05-04 22:22:20 +03:00
parent cda54b1e95
commit ebd77a3e66
54 changed files with 1194 additions and 2580 deletions

View File

@@ -8,10 +8,10 @@ import {
import routes from './routes'
import { useAuthStore } from 'stores/auth'
import { useProjectsStore } from 'stores/projects'
const tg = window.Telegram?.WebApp
declare module 'vue-router' {
interface RouteMeta {
public?: boolean
guestOnly?: boolean
hideBackButton?: boolean
backRoute?: string
@@ -32,29 +32,14 @@ export default defineRouter(function (/* { store, ssrContext } */) {
history: createHistory(process.env.VUE_ROUTER_BASE)
})
Router.beforeEach(async (to) => {
Router.beforeEach((to) => {
const authStore = useAuthStore()
if (!authStore.isInitialized) {
await authStore.initialize()
}
if (to.meta.guestOnly && authStore.isAuthenticated) {
if (to.meta.guestOnly && authStore.isAuth) {
return { name: 'projects' }
}
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
return {
name: 'login',
replace: true
}
}
if (to.meta.public) {
return true
}
if (!to.meta.public && !authStore.isAuthenticated) {
if (to.meta.requiresAuth && !authStore.isAuth) {
return {
name: 'login',
replace: true
@@ -67,17 +52,19 @@ export default defineRouter(function (/* { store, ssrContext } */) {
if (currentRoute.meta.backRoute) {
await Router.push({ name: currentRoute.meta.backRoute })
} else {
if (window.history.length > 1) Router.go(-1)
if (window.history.length > 1) Router.go(-1)
else await Router.push({ name: 'projects' })
}
}
Router.afterEach((to) => {
const BackButton = window.Telegram?.WebApp?.BackButton
if (BackButton) {
BackButton[to.meta.hideBackButton ? 'hide' : 'show']()
BackButton.offClick(handleBackButton as () => void)
BackButton.onClick(handleBackButton as () => void)
if (tg) {
const BackButton = tg?.BackButton
if (BackButton) {
BackButton[to.meta.hideBackButton ? 'hide' : 'show']()
BackButton.offClick(handleBackButton as () => void)
BackButton.onClick(handleBackButton as () => void)
}
}
if (!to.params.id) {