auth.js 1.2 KB

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