Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/api/Login/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ export const login = async (id, pw) => {
url: "/login",
data: { password: pw, username: id },
});
console.log("login res=================================", res);
return res;
};
5 changes: 3 additions & 2 deletions core/api/Login/roleTypeCheck.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Api, { METHOD } from "../apiController";
export const getUserRoleType = async (token) => {
export const getUserRoleType = async () => {
const res = await Api({
method: METHOD.GET,
url: "/session-user",
headers: { Authorization: token },
// headers: { Authorization: token },
});
console.log(res);
return res.data;
};
5 changes: 3 additions & 2 deletions core/api/Mentee/getLecture.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import qs from "qs";
import Api, { METHOD } from "../apiController";

export const getLecture = async (token, data) => {
export const getLecture = async (data) => {
const res = await Api({
method: METHOD.GET,
headers: { Authorization: token },
// headers: { Authorization: token },
url: "/lectures",
params: data,
paramsSerializer: (params) => {
return qs.stringify(params, { arrayFormat: "repeat" });
},
});

return res.data;
};
20 changes: 13 additions & 7 deletions core/api/apiController.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import axios from "axios";
import { getSession } from "next-auth/react";

let isRefresh = false;
const myAxios = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
});

myAxios.interceptors.request.use(
async (config) => {
isRefresh =
config.headers.common["X-Access-Token"] === undefined ? false : true;
const defaultHeader = axios.defaults.headers.common.Authorization;
console.log("header=====", defaultHeader);
// if (session) {
// config.headers.common["Authorization"] = defaultHeader;
// }
return config;
},
(err) => {
console.log(err);
return Promise.reject(err);
}
);

myAxios.interceptors.response.use(
async function (response) {
console.log("isRefresh====", isRefresh);
if (isRefresh) {
myAxios(config);
return response;
}
// if (isRefresh) {
// myAxios(config);
// return response;
// }
return response;
},
async function (error) {
console.log(error.response);
return error.response;
}
);
Expand Down
Loading