Skip to content

Commit

Permalink
Feat: chat instance에 토큰 얹기
Browse files Browse the repository at this point in the history
  • Loading branch information
soulchicken committed Oct 10, 2023
1 parent 20882a7 commit dcdd07e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/utils/axiosInstance/chatInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ const chatInstance = axios.create({

chatInstance.interceptors.response.use((response) => response, (error: AxiosError) => {
if (error.response && error.response.status === 401) {
console.error('ERROR');
console.error('ERROR', error.toJSON());
}
return Promise.reject(error);
});

chatInstance.interceptors.request.use(
async (config) => {
// Next-Auth의 getSession을 사용하여 서버측이나 클라이언트 측에서 세션 정보 가져오기
const session = await getSession();
console.log('\n\n\n--------session--------\n\n\n', session);
// const token = session?.accessToken;
const token = process.env.EXAMPLE_TOKEN;

const token = session?.accessToken;

if (token) {
// eslint-disable-next-line no-param-reassign
Expand Down
2 changes: 1 addition & 1 deletion src/utils/axiosInstance/clientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const clientInstance = axios.create({

clientInstance.interceptors.response.use((response) => response, (error: AxiosError) => {
if (error.response && error.response.status === 401) {
console.error('ERROR');
console.error('ERROR', error.toJSON());
}
return Promise.reject(error);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/axiosInstance/defaultInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const defaultInstance = axios.create({

defaultInstance.interceptors.response.use((response) => response, (error: AxiosError) => {
if (error.response && error.response.status === 401) {
console.error('ERROR');
console.error('ERROR', error.toJSON());
}
return Promise.reject(error);
});
Expand Down

0 comments on commit dcdd07e

Please sign in to comment.