feat: похуйу

This commit is contained in:
2026-05-12 22:18:45 +03:00
parent 929d455b30
commit a43c75a3df
5 changed files with 50 additions and 20 deletions

View File

@@ -1,17 +1,33 @@
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<unknown> {
export interface MeResponse {
id: string
email: string
first_name: string
middle_name: string
last_name: string
birth_date: string
crypto_wallet: string | null
phone: string
passport_data: string | null
inn: string | null
erc20: string | null
kyc_verified: boolean
is_deleted: boolean
created_at: string
updated_at: string
kyc_verified_at: string | null
}
export async function getMe(): Promise<MeResponse> {
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}` } : {}),
},
})

View File

@@ -44,5 +44,5 @@ export function loginComplete(payload: LoginCompletePayload): Promise<AuthRespon
export async function logout(): Promise<void> {
const csrfToken = await getCsrfToken()
return api.post<void>('/logout', { _csrf: csrfToken })
return api.post<void>('/auth/logout', { _csrf: csrfToken })
}

View File

@@ -0,0 +1,13 @@
import { useQuery } from '@tanstack/react-query'
import { getMe } from '../api/profileApi'
import type { MeResponse } from '../api/profileApi'
export function useMe() {
return useQuery<MeResponse>({
queryKey: ['me'],
queryFn: getMe,
staleTime: Infinity,
gcTime: Infinity,
retry: false,
})
}

View File

@@ -1,5 +1,7 @@
export { registrationStart, registrationComplete, loginStart, loginComplete } from './api/registrationApi'
export { getMe } from './api/profileApi'
export type { MeResponse } from './api/profileApi'
export { useMe } from './hooks/useMe'
export type { RegistrationStartPayload, RegistrationCompletePayload, LoginStartPayload, LoginCompletePayload, AuthResponse } from './api/registrationApi'
export { useIsAuthenticated } from './hooks/useIsAuthenticated'
export { useAuth, AUTH_QUERY_KEY } from './hooks/useAuth'