fix: error email validation
This commit is contained in:
parent
1e6d3368e1
commit
7f6485ae0e
|
|
@ -44,8 +44,8 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
|
|||
setLoadingPersonel(true);
|
||||
try {
|
||||
const res = await fetch(
|
||||
// `https://mediahub.polri.go.id/api/v2/public/users/search-personil?nrp=${nrp}&timemilis=${Date.now()}`
|
||||
`https://mediahub.polri.go.id/api/v2/public/users/search-personil?nrp=${nrp}}`
|
||||
`https://mediahub.polri.go.id/api/v2/public/users/search-personil?nrp=${nrp}&timemilis=${Date.now()}`
|
||||
// `https://mediahub.polri.go.id/api/v2/public/users/search-personil?nrp=${nrp}}`
|
||||
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@ const baseURL = "https://mediahub.polri.go.id/api/v2/";
|
|||
const refreshToken = Cookies.get("refresh_token");
|
||||
|
||||
// Helper function to append timestamp to URL to prevent caching
|
||||
// function addTimestampToUrl(url: string): string {
|
||||
// const separator = url.includes('?') ? '&' : '?';
|
||||
// const timestamp = Date.now();
|
||||
// return `${url}${separator}timemilis=${timestamp}`;
|
||||
// }
|
||||
function addTimestampToUrl(url: string): string {
|
||||
const separator = url.includes("?") ? "&" : "?";
|
||||
const timestamp = Date.now();
|
||||
// return `${url}${separator}timemilis=${timestamp}`;
|
||||
return `${url}${separator}`;
|
||||
}
|
||||
|
||||
const axiosInterceptorInstance = axios.create({
|
||||
baseURL,
|
||||
|
|
@ -29,17 +30,17 @@ axiosInterceptorInstance.interceptors.request.use(
|
|||
if (config.headers)
|
||||
config.headers.Authorization = "Bearer " + accessToken;
|
||||
}
|
||||
|
||||
|
||||
// Add timestamp to URL to prevent caching
|
||||
// if (config.url) {
|
||||
// config.url = addTimestampToUrl(config.url);
|
||||
// }
|
||||
|
||||
if (config.url) {
|
||||
config.url = addTimestampToUrl(config.url);
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Response interceptor
|
||||
|
|
@ -77,7 +78,7 @@ axiosInterceptorInstance.interceptors.response.use(
|
|||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
export default axiosInterceptorInstance;
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@ let csrfTokenExpiry: number = 0;
|
|||
const CSRF_CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
// Helper function to append timestamp to URL to prevent caching
|
||||
// function addTimestampToUrl(url: string): string {
|
||||
// const separator = url.includes('?') ? '&' : '?';
|
||||
// const timestamp = Date.now();
|
||||
// return `${url}${separator}timemilis=${timestamp}`;
|
||||
// }
|
||||
function addTimestampToUrl(url: string): string {
|
||||
const separator = url.includes("?") ? "&" : "?";
|
||||
const timestamp = Date.now();
|
||||
// return `${url}${separator}timemilis=${timestamp}`;
|
||||
return `${url}${separator}`;
|
||||
}
|
||||
|
||||
async function getCachedCsrfToken() {
|
||||
const now = Date.now();
|
||||
|
|
@ -59,14 +60,10 @@ export async function httpPost(pathUrl: any, data?: any, headers?: any) {
|
|||
};
|
||||
|
||||
// Add timestamp to URL to prevent caching
|
||||
// const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
const response = await axiosBaseInstance
|
||||
.post(
|
||||
// urlWithTimestamp,
|
||||
data,
|
||||
{ headers: mergedHeaders },
|
||||
)
|
||||
.post(urlWithTimestamp, data, { headers: mergedHeaders })
|
||||
.catch(function (error: any) {
|
||||
console.log(error);
|
||||
return error.response;
|
||||
|
|
@ -87,55 +84,55 @@ export async function httpPost(pathUrl: any, data?: any, headers?: any) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function httpGet(pathUrl: any, headers: any) {
|
||||
const response = await axiosBaseInstance
|
||||
.get(pathUrl, { headers })
|
||||
.catch(function (error: any) {
|
||||
console.log(error);
|
||||
return error.response;
|
||||
});
|
||||
|
||||
if (response?.status === 200 || response?.status === 201) {
|
||||
return {
|
||||
error: false,
|
||||
message: "success",
|
||||
data: response?.data,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
error: true,
|
||||
message: response?.data?.message || response?.data || null,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
// export async function httpGet(pathUrl: any, headers: any) {
|
||||
// // Add timestamp to URL to prevent caching
|
||||
// const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
// const response = await axiosBaseInstance
|
||||
// .get(urlWithTimestamp, { headers })
|
||||
// .get(pathUrl, { headers })
|
||||
// .catch(function (error: any) {
|
||||
// console.log(error);
|
||||
// return error.response;
|
||||
// });
|
||||
// // Remove console.log for better performance
|
||||
// if (response?.status == 200 || response?.status == 201) {
|
||||
|
||||
// if (response?.status === 200 || response?.status === 201) {
|
||||
// return {
|
||||
// error: false,
|
||||
// message: "success",
|
||||
// data: response?.data,
|
||||
// };
|
||||
// } else {
|
||||
// return {
|
||||
// error: true,
|
||||
// message: response?.data?.message || response?.data || null,
|
||||
// data: null,
|
||||
// };
|
||||
// }
|
||||
|
||||
// return {
|
||||
// error: true,
|
||||
// message: response?.data?.message || response?.data || null,
|
||||
// data: null,
|
||||
// };
|
||||
// }
|
||||
|
||||
export async function httpGet(pathUrl: any, headers: any) {
|
||||
// Add timestamp to URL to prevent caching
|
||||
const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
const response = await axiosBaseInstance
|
||||
.get(urlWithTimestamp, { headers })
|
||||
.catch(function (error: any) {
|
||||
console.log(error);
|
||||
return error.response;
|
||||
});
|
||||
// Remove console.log for better performance
|
||||
if (response?.status == 200 || response?.status == 201) {
|
||||
return {
|
||||
error: false,
|
||||
message: "success",
|
||||
data: response?.data,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
error: true,
|
||||
message: response?.data?.message || response?.data || null,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export async function httpPut(pathUrl: any, headers: any, data?: any) {
|
||||
const resCsrf = await getCsrfToken();
|
||||
const csrfToken = resCsrf?.data?.token;
|
||||
|
|
@ -151,12 +148,10 @@ export async function httpPut(pathUrl: any, headers: any, data?: any) {
|
|||
};
|
||||
|
||||
// Add timestamp to URL to prevent caching
|
||||
// const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
const response = await axiosBaseInstance
|
||||
.put(
|
||||
// urlWithTimestamp,
|
||||
data, { headers: mergedHeaders })
|
||||
.put(urlWithTimestamp, data, { headers: mergedHeaders })
|
||||
.catch(function (error: any) {
|
||||
console.log(error);
|
||||
return error.response;
|
||||
|
|
|
|||
Loading…
Reference in New Issue