corrections after the code review
test-org/trust-module-frontend/pipeline/pr-rc This commit looks good
Details
test-org/trust-module-frontend/pipeline/pr-rc This commit looks good
Details
parent
54cf5504a4
commit
b4d653f3a6
|
|
@ -5,6 +5,7 @@ import LoginModal from "./Components/UI/LoginModal";
|
|||
import { lightTheme, darkTheme } from "./Style/theme";
|
||||
import Logo from './assets/images/logo.svg?react';
|
||||
import { checkAuth } from "./Components/UI/auth";
|
||||
import axios from 'axios';
|
||||
|
||||
function App() {
|
||||
const [authState, setAuthState] = useState({
|
||||
|
|
@ -56,7 +57,7 @@ function App() {
|
|||
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
await fetch('http://192.168.2.39:3000/api/auth/logout', {
|
||||
await axios.get(`${import.meta.env.VITE_BACK_URL}/api/metrics`, {
|
||||
method: 'POST',
|
||||
credentials: 'include'
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import Modal from "./Modal";
|
|||
import "../../Style/LoginModal.css";
|
||||
import Logo from '../../assets/images/logo.svg?react';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import axios from 'axios';
|
||||
|
||||
const LoginModal = ({ onLogin, onClose }) => {
|
||||
const [username, setUsername] = useState("");
|
||||
|
|
@ -16,7 +17,8 @@ const LoginModal = ({ onLogin, onClose }) => {
|
|||
e.preventDefault();
|
||||
|
||||
try {
|
||||
const response = await fetch('http://192.168.2.39:3000/api/auth/login', {
|
||||
const response = await axios.post(
|
||||
`${import.meta.env.VITE_BACK_URL}/api/auth/login`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,25 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export const checkAuth = async () => {
|
||||
try {
|
||||
const response = await fetch('http://192.168.2.39:3000/api/auth/check', {
|
||||
method: 'GET',
|
||||
credentials: 'include', // Важно для отправки cookies
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('access_token') || ''}`,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${import.meta.env.VITE_BACK_URL}/api/auth/check`,
|
||||
{
|
||||
withCredentials: true, // аналог `credentials: 'include'` в fetch
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem('access_token') || ''}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Not authenticated');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (err) {
|
||||
console.error('Auth check failed:', err);
|
||||
return { isAuthenticated: false };
|
||||
// У axios нет свойства .ok, проверяем статус 200-299
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response.data; // Данные уже в JSON, не нужно .json()
|
||||
} else {
|
||||
throw new Error('Not authenticated');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Auth check failed:', err);
|
||||
return { isAuthenticated: false };
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue