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