1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

fix: do not use formatApiPath on paths from API (#702)

* fix: do not use formatApiPath on paths from API

* fix: remove createRequest
This commit is contained in:
Fredrik Strand Oseberg 2022-02-11 12:13:03 +01:00 committed by GitHub
parent 4a013c125f
commit 972ea43dfc

View File

@ -1,3 +1,4 @@
import { headers } from '../../../../utils/api-utils';
import useAPI from '../useApi/useApi';
type PasswordLogin = (
@ -16,24 +17,36 @@ interface IUseAuthApiOutput {
}
export const useAuthApi = (): IUseAuthApiOutput => {
const { makeRequest, createRequest, errors, loading } = useAPI({
const { makeRequest, errors, loading } = useAPI({
propagateErrors: true,
});
const passwordAuth = (path: string, username: string, password: string) => {
const req = createRequest(ensureRelativePath(path), {
method: 'POST',
body: JSON.stringify({ username, password }),
});
const req = {
caller: () => {
return fetch(path, {
headers,
method: 'POST',
body: JSON.stringify({ username, password }),
});
},
id: 'passwordAuth',
};
return makeRequest(req.caller, req.id);
};
const emailAuth = (path: string, email: string) => {
const req = createRequest(ensureRelativePath(path), {
method: 'POST',
body: JSON.stringify({ email }),
});
const req = {
caller: () => {
return fetch(path, {
headers,
method: 'POST',
body: JSON.stringify({ email }),
});
},
id: 'emailAuth',
};
return makeRequest(req.caller, req.id);
};