Added environment variables
test-org/trust-module-frontend/pipeline/pr-main This commit looks good Details
test-org/trust-module-frontend/pipeline/pr-rc This commit looks good Details

pull/40/head
DmitriyA 2025-05-28 01:47:18 -04:00
parent 4088dacba4
commit 8223cc4a27
3 changed files with 39 additions and 41 deletions

View File

@ -53,15 +53,15 @@ function App() {
const handleLogout = async () => {
try {
await fetch('http://192.168.2.39:3000/api/auth/logout', {
method: 'POST',
credentials: 'include'
await axios.post(`${import.meta.env.VITE_BACK_URL}/api/auth/logout`, null, {
withCredentials: true, // чтобы отправлялись куки
});
localStorage.removeItem('access_token');
setAuthState({
isAuthenticated: false,
isLoading: false,
user: null
user: null,
});
setShowLoginModal(true);
} catch (error) {

View File

@ -17,16 +17,16 @@ const LoginModal = ({ onLogin, onClose }) => {
e.preventDefault();
try {
const response = await fetch('http://192.168.2.39:3000/api/auth/login', {
method: 'POST',
credentials: 'include',
const { data } = await axios.post(
`${import.meta.env.VITE_BACK_URL}/api/auth/login`,
{ login: username, password },
{
withCredentials: true,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ login: username, password }),
});
const data = await response.json();
}
);
if (data.success) {
localStorage.setItem('access_token', data.access_token);
@ -37,7 +37,7 @@ const LoginModal = ({ onLogin, onClose }) => {
}
} catch (err) {
console.error('Ошибка при отправке запроса:', err);
setError("Ошибка при подключении к серверу");
setError(err.response?.data?.message || "Ошибка при подключении к серверу");
}
};

View File

@ -2,19 +2,17 @@ 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
const { data } = await axios.get(
`${import.meta.env.VITE_BACK_URL}/api/auth/check`,
{
withCredentials: true,
headers: {
'Authorization': `Bearer ${localStorage.getItem('access_token') || ''}`,
},
});
if (!response.ok) {
throw new Error('Not authenticated');
}
);
return await response.json();
return data;
} catch (err) {
console.error('Auth check failed:', err);
return { isAuthenticated: false };