._.
This commit is contained in:
parent
653ba03fd6
commit
b194ec40bf
23
src/api.jsx
23
src/api.jsx
@ -1,12 +1,27 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const API_URL = 'http://localhost:8000/api'; // Убедитесь, что этот URL правильный
|
||||
const API_URL = 'http://localhost:8000/api';
|
||||
|
||||
export const loginUser = async (loginData) => {
|
||||
const params = new URLSearchParams();
|
||||
params.append('grant_type', 'password');
|
||||
params.append('username', loginData.login); // Используем login и password из переданных данных
|
||||
params.append('password', loginData.password);
|
||||
// params.append('scope', '');
|
||||
// params.append('client_id', 'string');
|
||||
// params.append('client_secret', 'string');
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${API_URL}/login`, loginData);
|
||||
const response = await axios.post(`${API_URL}/token`, params, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
});
|
||||
console.log(response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error.response.data;
|
||||
console.log('Ошибка при запросе:', error.response ? error.response.data : error);
|
||||
throw error.response ? error.response.data : error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -11,7 +11,7 @@ const Login = () => {
|
||||
|
||||
try {
|
||||
const userData = await loginUser({ login, password });
|
||||
|
||||
|
||||
} catch (error) {
|
||||
setError(error.detail ? error.detail : 'Ошибка авторизации');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user