F
This commit is contained in:
@@ -90,6 +90,25 @@ export async function passwordResetStart(payload: PasswordResetStartPayload): Pr
|
||||
}
|
||||
}
|
||||
|
||||
export async function updatePhone(phone: string): Promise<void> {
|
||||
const headers = await authedHeaders()
|
||||
|
||||
const res = await fetch(`${USERS_API_URL}/me/settings/phone`, {
|
||||
method: 'PATCH',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...headers,
|
||||
},
|
||||
body: JSON.stringify({ phone }),
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}))
|
||||
throw data
|
||||
}
|
||||
}
|
||||
|
||||
export interface PasswordResetCompletePayload {
|
||||
email: string
|
||||
code: string
|
||||
|
||||
12
src/features/auth/hooks/useUpdatePhone.ts
Normal file
12
src/features/auth/hooks/useUpdatePhone.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { updatePhone } from '../api/profileApi'
|
||||
|
||||
export function useUpdatePhone() {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<void, unknown, string>({
|
||||
mutationFn: updatePhone,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['me'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
export { registrationStart, registrationComplete, loginStart, loginComplete } from './api/registrationApi'
|
||||
export { getMe, uploadAvatar } from './api/profileApi'
|
||||
export { getMe, uploadAvatar, updatePhone } from './api/profileApi'
|
||||
export type { MeResponse, UploadAvatarPayload } from './api/profileApi'
|
||||
export { useMe } from './hooks/useMe'
|
||||
export { useUploadAvatar } from './hooks/useUploadAvatar'
|
||||
export { useUpdatePhone } from './hooks/useUpdatePhone'
|
||||
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