1
0

Развитие бека

1. Создание БД
2. Создание бека
3. Пока создали класс юзера
This commit is contained in:
2026-01-11 17:48:05 +07:00
parent 301e179160
commit a9c146b192
9 changed files with 351 additions and 15 deletions

View File

@@ -9,14 +9,24 @@ const request = async (endpoint, options = {}) => {
// ==================== AUTH ====================
export const authApi = {
login: (data) => request('/auth', {
login: (username, password) => request('/api/user', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
body: JSON.stringify({ action: 'auth_login', username, password })
}),
check: () => request('/check-auth', { credentials: 'include' }),
logout: () => request('/logout', { credentials: 'include' })
check: () => request('/api/user', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'check_session' })
}),
logout: () => request('/api/user', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'logout' })
})
}
// ==================== DEPARTMENTS ====================
@@ -57,5 +67,5 @@ export const cardsApi = {
// ==================== USERS ====================
export const usersApi = {
getAll: () => request('/users', { credentials: 'include' })
getAll: () => request('/api/user', { credentials: 'include' })
}

View File

@@ -8,7 +8,7 @@ import { authApi } from './api'
const checkAuth = async () => {
try {
const data = await authApi.check()
return data.status === 'ok'
return data.success === true
} catch {
return false
}

View File

@@ -60,15 +60,12 @@ const handleLogin = async () => {
loading.value = true
try {
const data = await authApi.login({
login: login.value,
password: password.value
})
const data = await authApi.login(login.value, password.value)
if (data.status === 'ok') {
if (data.success) {
router.push('/')
} else {
error.value = 'Неверный логин или пароль'
error.value = data.errors?.username || data.errors?.password || 'Неверный логин или пароль'
}
} catch (e) {
error.value = 'Ошибка подключения к серверу'