feat: похуйу
This commit is contained in:
@@ -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}` } : {}),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -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 })
|
||||
}
|
||||
|
||||
13
src/features/auth/hooks/useMe.ts
Normal file
13
src/features/auth/hooks/useMe.ts
Normal 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,
|
||||
})
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user