From e310eafa1ea729fcc99186d539562a7c63ab0331 Mon Sep 17 00:00:00 2001 From: rassadin11 Date: Tue, 12 May 2026 21:50:41 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BF=D0=BE=D1=85=D1=83=D0=B9=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/auth/api/profileApi.ts | 21 +++++++++++++++++++++ src/features/auth/index.ts | 1 + src/pages/profile/ui/ProfilePage.tsx | 8 +++----- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/features/auth/api/profileApi.ts diff --git a/src/features/auth/api/profileApi.ts b/src/features/auth/api/profileApi.ts new file mode 100644 index 0000000..24a86ef --- /dev/null +++ b/src/features/auth/api/profileApi.ts @@ -0,0 +1,21 @@ +import { getCsrfToken } from '@shared/api/csrf' +import { tokenStore } from '@shared/api/tokenStore' + +const USERS_API_URL = 'https://app.users.elcsa.ru' + +export async function getMe(): Promise { + const csrf = await getCsrfToken() + const bearer = tokenStore.get() + + const res = await fetch(`${USERS_API_URL}/me`, { + credentials: 'include', + headers: { + 'X-CSRF-Token': csrf, + ...(bearer ? { Authorization: `Bearer ${bearer}` } : {}), + }, + }) + + const data = await res.json() + if (!res.ok) throw data + return data +} diff --git a/src/features/auth/index.ts b/src/features/auth/index.ts index c373a4c..d1d2229 100644 --- a/src/features/auth/index.ts +++ b/src/features/auth/index.ts @@ -1,4 +1,5 @@ export { registrationStart, registrationComplete, loginStart, loginComplete } from './api/registrationApi' +export { getMe } from './api/profileApi' export type { RegistrationStartPayload, RegistrationCompletePayload, LoginStartPayload, LoginCompletePayload, AuthResponse } from './api/registrationApi' export { useIsAuthenticated } from './hooks/useIsAuthenticated' export { useAuth, AUTH_QUERY_KEY } from './hooks/useAuth' diff --git a/src/pages/profile/ui/ProfilePage.tsx b/src/pages/profile/ui/ProfilePage.tsx index b9b3922..0b9ffbf 100644 --- a/src/pages/profile/ui/ProfilePage.tsx +++ b/src/pages/profile/ui/ProfilePage.tsx @@ -1,4 +1,5 @@ import { useEffect } from 'react' +import { getMe } from '@features/auth' import { Button, FormField } from '@shared/ui' import { WalletHeader } from '@widgets/wallet-header' import { ProfileAvatar, ProfileSection } from '@widgets/profile' @@ -6,11 +7,8 @@ import styles from './ProfilePage.module.css' export function ProfilePage() { useEffect(() => { - fetch('https://app.users.elcsa.ru/me', { credentials: 'include' }) - .then(async (res) => { - const data = await res.json().catch(() => null) - console.log('[/me] status:', res.status, 'body:', data) - }) + getMe() + .then((data) => console.log('[/me]', data)) .catch((err) => console.error('[/me] error:', err)) }, [])