fix(#2227): fix auth file
parent
e57e645fc6
commit
78728aaea3
@ -1,61 +0,0 @@ |
|||||||
import { getClientSettings } from 'features/AuthStore/helpers' |
|
||||||
|
|
||||||
import { getApiUrl } from '../config/routes' |
|
||||||
|
|
||||||
const errorLexics = { |
|
||||||
1: 'error_invalid_email_or_password', |
|
||||||
4: 'error_user_not_found', |
|
||||||
} |
|
||||||
|
|
||||||
type FailedResponse = { |
|
||||||
error: { |
|
||||||
code: keyof typeof errorLexics, |
|
||||||
message?: string, |
|
||||||
}, |
|
||||||
ok: false, |
|
||||||
} |
|
||||||
|
|
||||||
type SuccessResponse = { |
|
||||||
ok: true, |
|
||||||
} |
|
||||||
|
|
||||||
export const loginCheck = async ( |
|
||||||
email: string, |
|
||||||
lang: string, |
|
||||||
password: string, |
|
||||||
redirect_uri: string | undefined, |
|
||||||
) => { |
|
||||||
const { |
|
||||||
client_id, |
|
||||||
response_mode, |
|
||||||
response_type, |
|
||||||
scope, |
|
||||||
} = getClientSettings() |
|
||||||
|
|
||||||
const paramsUrl = { |
|
||||||
client_id, |
|
||||||
lang, |
|
||||||
redirect_uri, |
|
||||||
response_mode, |
|
||||||
response_type, |
|
||||||
scope, |
|
||||||
} |
|
||||||
|
|
||||||
const url = getApiUrl('/authorize-check') |
|
||||||
|
|
||||||
const init: RequestInit = { |
|
||||||
body: new URLSearchParams({ |
|
||||||
email, |
|
||||||
password, |
|
||||||
...paramsUrl as {}, |
|
||||||
}), |
|
||||||
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]) |
|
||||||
} |
|
||||||
Loading…
Reference in new issue