You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
spa_instat_tv/src/features/AuthServiceApp/requests/loginCheck.tsx

35 lines
724 B

import { getApiUrl } from '../config/routes'
const errorLexics = {
4: 'error_user_not_found_recovery',
8: 'error_failed_to_send_email',
}
type FailedResponse = {
error: {
code: keyof typeof errorLexics,
message?: string,
},
ok: false,
}
type SuccessResponse = {
ok: true,
}
export const loginCheckChangePass = async (email: string) => {
const url = getApiUrl('/change_password')
const init: RequestInit = {
body: new URLSearchParams({
email,
}),
method: 'POST',
}
const response = await fetch(url, init)
const body: SuccessResponse | FailedResponse = await response.json()
if (body.ok) return Promise.resolve()
return Promise.reject(errorLexics[body.error.code])
}