ilink-world/webservice/AuthKeyApi.js

29 lines
1.0 KiB
JavaScript

import axios from "axios";
import { authKeyUrl, authKeyData } from "./IlinkConstants";
import { fetchAuthKeySuccess, fetchAuthKeyPending, fetchAuthKeyError } from "../redux/actions/AuthKeyActions";
const getAuthApiKey = (phone) => {
const data = authKeyData;
authKeyData.username = phone;
authKeyData.password = "";
return dispatch => {
dispatch(fetchAuthKeyPending());
axios.post(authKeyUrl, authKeyData)
.then(response => {
dispatch(fetchAuthKeySuccess(response));
})
.catch(error => {
dispatch(fetchAuthKeyError(error.message));
if (error.response)
dispatch(fetchAuthKeyError(error.response));
else if (error.request)
dispatch(fetchAuthKeyError(error.request))
else
dispatch(fetchAuthKeyError(error.message))
});
}
}
export default getAuthApiKey;