5_10
This commit is contained in:
parent
3ba9000675
commit
c25c2a63f1
@ -13,13 +13,6 @@
|
||||
"name": "Pek",
|
||||
"role": "user",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"email": "Goka.2004@yandex.ru",
|
||||
"password": "1111",
|
||||
"name": "Admin1",
|
||||
"role": "user",
|
||||
"id": 3
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
|
@ -24,6 +24,10 @@ class ApiService {
|
||||
async delete(id) {
|
||||
return ApiClient.delete(`${this.url}/${id}`);
|
||||
}
|
||||
|
||||
async getOneByName(name) {
|
||||
return ApiClient.get(`${this.url}?name=${name}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default ApiService;
|
||||
|
@ -6,13 +6,19 @@ class AuthService extends ApiService {
|
||||
}
|
||||
|
||||
async loginUser(credentials) {
|
||||
const users = await this.getAll();
|
||||
// eslint-disable-next-line max-len
|
||||
const user = users.find((u) => u.email === credentials.email && u.password === credentials.password);
|
||||
const user = await this.getOneByName(credentials.name);
|
||||
if (!user) {
|
||||
throw new Error('Invalid name');
|
||||
}
|
||||
const item = user[0];
|
||||
console.log(item.name);
|
||||
if (item && item.password !== credentials.password) {
|
||||
throw new Error('Invalid email or password');
|
||||
}
|
||||
return user;
|
||||
if (item && item.email !== credentials.email) {
|
||||
throw new Error('Invalid email or password');
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
async registerUser(userData) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { useContext, useState } from 'react';
|
||||
import { Form, Button } from 'react-bootstrap';
|
||||
import { Link } from 'react-router-dom';
|
||||
import toast from 'react-hot-toast';
|
||||
import AuthService from '../../api/AuthService';
|
||||
import { AuthContext } from '../context/AuthContex.jsx';
|
||||
|
||||
@ -22,7 +23,7 @@ const LoginForm = () => {
|
||||
payload: user,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Login error', error);
|
||||
toast.error('Entry ERROR');
|
||||
}
|
||||
};
|
||||
|
||||
@ -35,7 +36,7 @@ const LoginForm = () => {
|
||||
payload: user,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Register error', error);
|
||||
toast.error('Register ERROR');
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user