Развитие бека
1. Создание БД 2. Создание бека 3. Пока создали класс юзера
This commit is contained in:
@@ -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' })
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 = 'Ошибка подключения к серверу'
|
||||
|
||||
Reference in New Issue
Block a user