feat: update csrf on http base services
This commit is contained in:
parent
9bce4dd24f
commit
c8f95aa101
|
|
@ -8,18 +8,10 @@ import {
|
||||||
} from "./http-config/http-interceptor-service";
|
} from "./http-config/http-interceptor-service";
|
||||||
|
|
||||||
export async function login(data: any) {
|
export async function login(data: any) {
|
||||||
|
|
||||||
const res = await getCsrfToken();
|
|
||||||
const csrfToken = res?.data?.token;
|
|
||||||
|
|
||||||
|
|
||||||
console.log("Token CSRF : ", csrfToken);
|
|
||||||
|
|
||||||
const pathUrl = "signin";
|
const pathUrl = "signin";
|
||||||
const headers = {
|
const headers = {
|
||||||
'accept': 'application/json',
|
'accept': 'application/json',
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
'X-XSRF-TOKEN': csrfToken
|
|
||||||
};
|
};
|
||||||
return httpPost(pathUrl, headers, data);
|
return httpPost(pathUrl, headers, data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,24 @@ import axiosBaseInstance from "./axios-base-instance";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
|
import { getCsrfToken } from "../auth";
|
||||||
|
|
||||||
export async function httpPost(pathUrl: any, headers: any, data?: any) {
|
export async function httpPost(pathUrl: any, headers: any, data?: any) {
|
||||||
const response = await axiosBaseInstance
|
const resCsrf = await getCsrfToken();
|
||||||
.post(pathUrl, data, { headers })
|
const csrfToken = resCsrf?.data?.token;
|
||||||
|
|
||||||
|
const defaultHeaders = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
};
|
||||||
|
|
||||||
|
const mergedHeaders = {
|
||||||
|
...defaultHeaders,
|
||||||
|
...headers,
|
||||||
|
...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await axiosBaseInstance
|
||||||
|
.post(pathUrl, data, { headers: mergedHeaders })
|
||||||
.catch(function (error: any) {
|
.catch(function (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return error.response;
|
return error.response;
|
||||||
|
|
@ -50,8 +64,21 @@ export async function httpGet(pathUrl: any, headers: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 csrfToken = resCsrf?.data?.token;
|
||||||
|
|
||||||
|
const defaultHeaders = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
};
|
||||||
|
|
||||||
|
const mergedHeaders = {
|
||||||
|
...defaultHeaders,
|
||||||
|
...headers,
|
||||||
|
...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
const response = await axiosBaseInstance
|
const response = await axiosBaseInstance
|
||||||
.put(pathUrl, data, { headers })
|
.put(pathUrl, data, { headers: mergedHeaders })
|
||||||
.catch(function (error: any) {
|
.catch(function (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return error.response;
|
return error.response;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue