diff --git a/WEB/src/router/index.js b/WEB/src/router/index.js
index d322c34..e396b8e 100644
--- a/WEB/src/router/index.js
+++ b/WEB/src/router/index.js
@@ -1,23 +1,12 @@
-import {createRouter, createWebHistory} from 'vue-router'
+import { createRouter, createWebHistory } from 'vue-router'
import LoginPage from "../pages/LoginPage.vue"
import HomePage from "../pages/HomePage.vue"
import AdminPage from "../pages/AdminPage.vue"
-import { isAuthenticated, getUserRole } from "../utils/auth.js"
const routes = [
- {
- path: '/',
- component: HomePage
- },
- {
- path: '/login',
- component: LoginPage
- },
- {
- path: '/admin',
- component: AdminPage,
- meta: { requiresAuth: true, requiresAdmin: true }
- }
+ { path: '/', component: HomePage },
+ { path: '/login', component: LoginPage },
+ { path: '/admin', component: AdminPage }
]
const router = createRouter({
@@ -26,30 +15,20 @@ const router = createRouter({
})
router.beforeEach((to, from, next) => {
- const authenticated = isAuthenticated()
+ const isAuthenticated = !!localStorage.getItem('access_token')
+ const userId = localStorage.getItem('user_id')
- // Если переходим на страницу логина и уже авторизованы
- if (to.path === '/login' && authenticated) {
+ if (to.path === '/login' && isAuthenticated) {
next('/')
- return
- }
-
- // Проверка доступа к админ-панели
- if (to.meta.requiresAdmin) {
- if (!authenticated) {
- next('/login')
- return
- }
-
- const userRole = getUserRole()
- if (userRole !== 'admin') {
- // Редирект на главную, если не админ
+ } else if (to.path === '/admin') {
+ if (isAuthenticated && userId === '1') {
+ next()
+ } else {
next('/')
- return
}
+ } else {
+ next()
}
-
- next()
})
-export default router
\ No newline at end of file
+export default router
diff --git a/WEB/src/utils/auth.js b/WEB/src/utils/auth.js
deleted file mode 100644
index acef0ec..0000000
--- a/WEB/src/utils/auth.js
+++ /dev/null
@@ -1,35 +0,0 @@
-export const decodeToken = (token) => {
- try {
- const base64Url = token.split('.')[1]
- const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/')
- const jsonPayload = decodeURIComponent(
- atob(base64)
- .split('')
- .map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
- .join('')
- )
- return JSON.parse(jsonPayload)
- } catch (error) {
- console.error('Ошибка декодирования токена:', error)
- return null
- }
-}
-
-export const getUserRole = () => {
- const token = localStorage.getItem('access_token')
- if (!token) return null
-
- const decoded = decodeToken(token)
- return decoded?.role || null
-}
-
-
-
-export const isAuthenticated = () => {
- return !!localStorage.getItem('access_token')
-}
-
-
-export const isAdmin = () => {
- return getUserRole() === 'admin'
-}
\ No newline at end of file
diff --git a/WEB/vite.config.js b/WEB/vite.config.js
index bbcf80c..02c203c 100644
--- a/WEB/vite.config.js
+++ b/WEB/vite.config.js
@@ -1,7 +1,12 @@
+import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
-// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
-})
+ resolve: {
+ alias: {
+ '@': fileURLToPath(new URL('./src', import.meta.url))
+ }
+ }
+})
\ No newline at end of file