Files
no-copy-frontend/src/app/actions/action.ts
T

31 lines
758 B
TypeScript
Raw Normal View History

2025-11-25 17:13:16 +07:00
'use server'
2025-12-09 16:35:47 +07:00
import { getSessionData } from '@/app/actions/session';
2025-12-27 11:54:54 +07:00
import { testUserData, API_BASE_URL } from '@/app/actions/definitions';
2025-11-29 14:40:26 +07:00
2025-12-02 17:11:53 +07:00
export async function getUserData() {
const userEmail = await getSessionData('email');
const token = await getSessionData('token');
2025-12-11 18:28:35 +07:00
/* для теста */
if (userEmail === "test" && token === "1111") {
return testUserData;
}
/* для теста */
2025-11-25 17:13:16 +07:00
try {
2025-12-07 10:58:53 +07:00
const response = await fetch(`${API_BASE_URL}/v1/api/user?email=${userEmail}`, {
2025-12-02 17:11:53 +07:00
method: 'GET',
2025-11-25 17:13:16 +07:00
headers: {
"Content-Type": "application/json",
2025-12-02 17:11:53 +07:00
"Accept": "application/json",
"Authorization": `Bearer ${token}`,
2025-11-25 17:13:16 +07:00
}
});
2025-12-02 17:11:53 +07:00
if (response.ok) {
return await response.json();
}
2025-11-25 17:13:16 +07:00
} catch (error) {
2025-12-02 17:11:53 +07:00
console.error('error');
2025-11-25 17:13:16 +07:00
}
}