fix: error email validation

This commit is contained in:
Sabda Yagra 2026-01-21 16:31:27 +07:00
parent 1e6d3368e1
commit 7f6485ae0e
3 changed files with 60 additions and 64 deletions

View File

@ -44,8 +44,8 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
setLoadingPersonel(true); setLoadingPersonel(true);
try { try {
const res = await fetch( 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}&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}}`
); );

View File

@ -7,11 +7,12 @@ const baseURL = "https://mediahub.polri.go.id/api/v2/";
const refreshToken = Cookies.get("refresh_token"); const refreshToken = Cookies.get("refresh_token");
// Helper function to append timestamp to URL to prevent caching // Helper function to append timestamp to URL to prevent caching
// function addTimestampToUrl(url: string): string { function addTimestampToUrl(url: string): string {
// const separator = url.includes('?') ? '&' : '?'; const separator = url.includes("?") ? "&" : "?";
// const timestamp = Date.now(); const timestamp = Date.now();
// return `${url}${separator}timemilis=${timestamp}`; // return `${url}${separator}timemilis=${timestamp}`;
// } return `${url}${separator}`;
}
const axiosInterceptorInstance = axios.create({ const axiosInterceptorInstance = axios.create({
baseURL, baseURL,
@ -31,15 +32,15 @@ axiosInterceptorInstance.interceptors.request.use(
} }
// Add timestamp to URL to prevent caching // Add timestamp to URL to prevent caching
// if (config.url) { if (config.url) {
// config.url = addTimestampToUrl(config.url); config.url = addTimestampToUrl(config.url);
// } }
return config; return config;
}, },
(error) => { (error) => {
return Promise.reject(error); return Promise.reject(error);
} },
); );
// Response interceptor // Response interceptor
@ -77,7 +78,7 @@ axiosInterceptorInstance.interceptors.response.use(
} }
return Promise.reject(error); return Promise.reject(error);
} },
); );
export default axiosInterceptorInstance; export default axiosInterceptorInstance;

View File

@ -10,11 +10,12 @@ let csrfTokenExpiry: number = 0;
const CSRF_CACHE_DURATION = 5 * 60 * 1000; // 5 minutes const CSRF_CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
// Helper function to append timestamp to URL to prevent caching // Helper function to append timestamp to URL to prevent caching
// function addTimestampToUrl(url: string): string { function addTimestampToUrl(url: string): string {
// const separator = url.includes('?') ? '&' : '?'; const separator = url.includes("?") ? "&" : "?";
// const timestamp = Date.now(); const timestamp = Date.now();
// return `${url}${separator}timemilis=${timestamp}`; // return `${url}${separator}timemilis=${timestamp}`;
// } return `${url}${separator}`;
}
async function getCachedCsrfToken() { async function getCachedCsrfToken() {
const now = Date.now(); 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 // Add timestamp to URL to prevent caching
// const urlWithTimestamp = addTimestampToUrl(pathUrl); const urlWithTimestamp = addTimestampToUrl(pathUrl);
const response = await axiosBaseInstance const response = await axiosBaseInstance
.post( .post(urlWithTimestamp, data, { headers: mergedHeaders })
// urlWithTimestamp,
data,
{ headers: mergedHeaders },
)
.catch(function (error: any) { .catch(function (error: any) {
console.log(error); console.log(error);
return error.response; 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) { // export async function httpGet(pathUrl: any, headers: any) {
// // Add timestamp to URL to prevent caching
// const urlWithTimestamp = addTimestampToUrl(pathUrl);
// const response = await axiosBaseInstance // const response = await axiosBaseInstance
// .get(urlWithTimestamp, { headers }) // .get(pathUrl, { headers })
// .catch(function (error: any) { // .catch(function (error: any) {
// console.log(error); // console.log(error);
// return error.response; // return error.response;
// }); // });
// // Remove console.log for better performance
// if (response?.status == 200 || response?.status == 201) { // if (response?.status === 200 || response?.status === 201) {
// return { // return {
// error: false, // error: false,
// message: "success", // message: "success",
// data: response?.data, // 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) { export async function httpPut(pathUrl: any, headers: any, data?: any) {
const resCsrf = await getCsrfToken(); const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.token; 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 // Add timestamp to URL to prevent caching
// const urlWithTimestamp = addTimestampToUrl(pathUrl); const urlWithTimestamp = addTimestampToUrl(pathUrl);
const response = await axiosBaseInstance const response = await axiosBaseInstance
.put( .put(urlWithTimestamp, data, { headers: mergedHeaders })
// urlWithTimestamp,
data, { headers: mergedHeaders })
.catch(function (error: any) { .catch(function (error: any) {
console.log(error); console.log(error);
return error.response; return error.response;