mediahub-fe/service/auth.ts

85 lines
2.2 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";
import {
2025-01-01 17:48:57 +00:00
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 = {
'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 || ''
// }
// });
// 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() {
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'
// });
// 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);
// }
}
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
}