17.05.2026 funny

This commit is contained in:
2026-05-17 13:06:18 +03:00
parent 73d1fd9135
commit bd3d747ede
10 changed files with 157 additions and 39 deletions

View File

@@ -1,4 +1,5 @@
import { getCsrfToken } from '@shared/api/csrf'
import { tokenStore } from '@shared/api/tokenStore'
const USERS_API_URL = 'https://app.users.elcsa.ru'
@@ -9,26 +10,58 @@ export interface MeResponse {
middle_name: string
last_name: string
birth_date: string
crypto_wallet: string | null
encrypted_mnemonic: string | null
phone: string
passport_data: string | null
inn: string | null
erc20: string | null
avatar_link: string | null
kyc_verified: boolean
is_deleted: boolean
created_at: string
updated_at: string
kyc_verified_at: string | null
webp_size_bytes: number
}
export interface UploadAvatarPayload {
photo_base64: string
decoded_bytes: string
}
async function authedHeaders(): Promise<HeadersInit> {
const csrf = await getCsrfToken()
const bearer = tokenStore.get()
return {
'X-CSRF-Token': csrf,
...(bearer ? { Authorization: `Bearer ${bearer}` } : {}),
}
}
export async function getMe(): Promise<MeResponse> {
const csrf = await getCsrfToken()
const headers = await authedHeaders()
const res = await fetch(`${USERS_API_URL}/me/`, {
credentials: 'include',
headers: {
'X-CSRF-Token': csrf,
},
headers,
})
const data = await res.json()
if (!res.ok) throw data
return data
}
export async function uploadAvatar(payload: UploadAvatarPayload): Promise<MeResponse> {
const headers = await authedHeaders()
const res = await fetch(`${USERS_API_URL}/me/settings/avatar`, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
...headers,
},
body: JSON.stringify(payload),
})
const data = await res.json()

View File

@@ -0,0 +1,13 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { uploadAvatar } from '../api/profileApi'
import type { MeResponse, UploadAvatarPayload } from '../api/profileApi'
export function useUploadAvatar() {
const queryClient = useQueryClient()
return useMutation<MeResponse, unknown, UploadAvatarPayload>({
mutationFn: uploadAvatar,
onSuccess: (data) => {
queryClient.setQueryData(['me'], data)
},
})
}

View File

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