mediahub-fe/service/auth.ts

129 lines
3.6 KiB
TypeScript
Raw Normal View History

2025-01-02 05:13:05 +00:00
import qs from "qs";
import { getAPIDummy } from "./http-config/axiosCustom";
import { httpGet, httpPost } from "./http-config/http-base-service";
2025-01-13 15:12:28 +00:00
import { httpGetInterceptor, httpGetInterceptorWithToken, httpPostInterceptor } from "./http-config/http-interceptor-service";
2025-01-01 17:48:57 +00:00
export async function login(data: any) {
const pathUrl = "signin";
2025-01-02 05:13:05 +00:00
const headers = {
2025-01-13 15:12:28 +00:00
accept: "application/json",
"content-type": "application/json",
2025-01-02 05:13:05 +00:00
};
return httpPost(pathUrl, headers, data);
}
// export async function login(data: any, csrfToken: string) {
// const url = 'http://localhost:8080/mediahub/users/signin';
// try {
// const response = await fetch(url, {
// method: 'POST',
// credentials: 'include',
// headers: {
// 'Content-Type': 'application/json',
// 'X-XSRF-TOKEN': csrfToken || ''
// }
// });
2025-01-13 15:12:28 +00:00
// if (!response.ok) {
// throw new Error(`HTTP error! status: ${response.status}`);
// }
// return response; // Menampilkan data yang diterima dari API
// } catch (error) {
// console.error('Fetch error: ', error);
// }
// }
export async function getCsrfToken() {
2025-01-13 15:12:28 +00:00
const pathUrl = "csrf";
const headers = {
"content-type": "application/json",
};
return httpGet(pathUrl, headers);
// const url = 'https://netidhub.com/api/csrf';
// try {
// const response = await fetch(url, {
// method: 'GET',
// credentials: 'include'
// });
2025-01-13 15:12:28 +00:00
// if (!response.ok) {
// throw new Error(`HTTP error! status: ${response.status}`);
// }
2025-01-02 05:13:05 +00:00
// const data = await response.json();
// console.log("csrf : ", data);
// return data;
// } catch (error) {
// console.error('Fetch error: ', error);
// }
}
2025-01-15 15:59:19 +00:00
export async function getProfile(token: any) {
const url = "users/info";
2025-01-01 17:48:57 +00:00
return httpGetInterceptorWithToken(url, token);
}
2024-12-26 11:29:22 +00:00
export async function getInfoProfile() {
const url = "users/info";
2025-01-01 17:48:57 +00:00
return httpGetInterceptor(url);
2024-12-26 11:29:22 +00:00
}
export async function setupPassword(data: any) {
const url = "setup-password";
2025-01-01 17:48:57 +00:00
return httpPostInterceptor(url, data);
2024-12-26 11:29:22 +00:00
}
export async function saveUser(data: any) {
const url = "users/save";
2025-01-01 17:48:57 +00:00
return httpPostInterceptor(url, data);
2024-12-26 11:29:22 +00:00
}
2025-01-09 01:59:46 +00:00
export async function saveInstitutes(data: any) {
const url = "public/users/save-institutes";
return httpPostInterceptor(url, data);
}
export async function postRegistration(data: any) {
const url = "public/users/save";
return httpPostInterceptor(url, data);
}
export async function getDataByNIK(reqid: any, nik: any) {
const url = `http://spitpolri.com/api/back_end/get_ktp?reqid=${reqid}&nik=${nik}`;
return getAPIDummy(url);
}
export async function listInstitusi(roleId: any) {
const url = `public/users/institutes?categoryRoleId=${roleId}`;
return httpGetInterceptor(url);
}
export async function listProvince() {
const url = "public/users/provinces";
return httpGetInterceptor(url);
}
export async function listCity(id: any) {
const url = `public/users/cities?provId=${id}`;
return httpGetInterceptor(url);
}
export async function listDistricts(id: any) {
const url = `public/users/districts?cityId=${id}`;
return httpGetInterceptor(url);
}
export async function getDataByNRP(reqid: any, nrp: any) {
const url = `http://spitpolri.com/api/back_end/get_nrp?reqid=${reqid}&nrp=${nrp}`;
return getAPIDummy(url);
}
2025-01-09 01:59:46 +00:00
export async function getDataJournalist(cert: any) {
const url = `public/users/search-journalist?cert=${cert}`;
2025-01-13 15:12:28 +00:00
return httpGetInterceptor(url);
2025-01-09 01:59:46 +00:00
}
export async function getDataPersonil(nrp: any) {
const url = `public/users/search-personil?nrp=${nrp}`;
2025-01-13 15:12:28 +00:00
return httpGetInterceptor(url);
2025-01-09 01:59:46 +00:00
}