Grant Request Function
enum GRANT_RESPONSES {
FORBIDDEN = 'FORBIDDEN',
UNAUTHORIZED = 'UNAUTHORIZED',
GRANTED = 'GRANTED',
ERROR = 'ERROR',
}
type GrantRequestFunctionType = (grant: GrantRequest) => Promise<GRANT_RESPONSES>import axios from 'axios'
import {GrantRequestFunctionType, GRANT_RESPONSES} from 'ux4iot-react';
const UX4IOT_URL = 'https://ux4iot-xyz.westeurope.azurecontainer.io'
const CUSTOM_BACKEND = 'https://your-iot-app.com/api/ux4iot-grant-requests'
const customGrantRequestFunction: GrantRequestFunctionType = async grantRequest => {
const config = {
headers: {
Authorization: "Bearer " + getCurrentAccessToken()
}
};
try {
await axios.put(CUSTOM_BACKEND, grantRequest, config);
} catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
if (error.response.status === 401) {
return GRANT_RESPONSES.UNAUTHORIZED;
} else if (error.response.status === 403) {
return GRANT_RESPONSES.FORBIDDEN;
}
}
}
return GRANT_RESPONSES.ERROR;
}
return GRANT_RESPONSES.GRANTED;
};Last updated
Was this helpful?