auth.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { get } from "../config/request";
  2. import axiosAPI from "../config/axios";
  3. import { createLog } from "./log";
  4. import { getCsrf } from "./security";
  5. export const login = async (username, password) => {
  6. const data = {
  7. username,
  8. password,
  9. };
  10. const response = await axiosAPI.post("/auth/login", data, {
  11. headers: {
  12. "Content-Type": "application/json",
  13. },
  14. });
  15. return response.data;
  16. };
  17. export const refreshToken = async () => {
  18. try {
  19. const response = await axiosAPI.get("/token");
  20. return response.data;
  21. } catch (error) {
  22. if (error.response) return error.response.data;
  23. }
  24. };
  25. export const getUser = async () => {
  26. try {
  27. const response = await get("/user");
  28. return response.data;
  29. } catch (error) {
  30. if (error.response) return error.response.data;
  31. }
  32. };
  33. export const logout = async ( _csrf) => {
  34. try {
  35. const response = await axiosAPI.delete(`/auth/logout?_csrf=${_csrf}`);
  36. return response.data;
  37. } catch (error) {
  38. if (error.response) return error.response.data;
  39. }
  40. };
  41. export const loginToPt = async (lembaga_id, password, _csrf) => {
  42. const data = {
  43. lembaga_id,
  44. password,
  45. };
  46. const response = await axiosAPI.post(`/auth/login-to-pt?_csrf=${_csrf}`, data, {
  47. headers: {
  48. "Content-Type": "application/json",
  49. },
  50. });
  51. return response.data;
  52. };