Skip to content

Conversation

@jeschun
Copy link
Contributor

@jeschun jeschun commented Oct 11, 2025

📝 작업 개요 (필수)

공용 axios 인스턴스 도입 및 Authorization: Bearer 자동 첨부 구조 구축.
추가로 AuthProvider 전역 상태(토큰/사용자ID/내 정보)와 표준 함수(login / logout / getUser / updateUser)를 제공하고, 브라우저에서 바로 점검 가능한 **테스트 페이지(pages/testAuth.tsx)**를 추가했습니다.

✨ 작업 내용 (필수)

  • 기능 구현
  • 버그 수정
  • 스타일/UI 변경
  • 리팩토링
  • 최적화/성능개선
  • 문서 업데이트
  • 기타 변경사항

📸 스크린샷

🧐 해결해야 하는 문제

🤔 리뷰어 확인 필요 사항

🔗 관련 이슈

  • Closes #이슈 번호
  • Related to #이슈 번호

🛠️ 후속 작업

  • [ ]
  • [ ]

✅ 체크리스트 (필수)

  • 작업한 내용과 커밋 메시지 컨벤션을 통일했는지 확인
  • 내가 작성한 코드를 테스트까지 완료했는지 잘 작동했는지 확인
  • ESLint 검사 통과
  • Prettier 포맷팅 적용
  • TypeScript 에러 없음
  • 빌드 에러 없음

@jeschun jeschun self-assigned this Oct 11, 2025
@jeschun jeschun added ✨ feat 새로운 기능 추가 🔌 api API 연동 labels Oct 11, 2025
@vercel
Copy link

vercel bot commented Oct 11, 2025

@jeschun is attempting to deploy a commit to the projects Team on Vercel.

A member of the Team first needs to authorize it.

@jeschun jeschun moved this to In review in The-julge Oct 11, 2025
@jeschun jeschun linked an issue Oct 11, 2025 that may be closed by this pull request
4 tasks
@jeschun jeschun added the ♻️ refactor 결과 변화 없이 코드 구조 개선 label Oct 11, 2025
@vercel
Copy link

vercel bot commented Oct 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
thejulge Ready Ready Preview Comment Oct 13, 2025 7:06am

Copy link
Contributor

@sohyun0 sohyun0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다 ! 코멘트 확인 부탁드립니다
또한, any 타입을 제외한 모든 사항은 시간 여유가 있을때 리팩토링 제안이므로 참고해주세요!

Comment on lines 10 to 26
axiosInstance.interceptors.request.use(config => {
// SSR에서는 localStorage가 없으니 브라우저에서만 읽기
const token = typeof window !== 'undefined' ? localStorage.getItem('thejulge_token') : null;
if (token) {
// Axios v1: headers가 AxiosHeaders(클래스)일 수 있음
const h = config.headers as any;
if (h?.set && typeof h.set === 'function') {
// 1) AxiosHeaders 인스턴스인 경우: set API 지원
h.set('Authorization', `Bearer ${token}`);
} else {
// 2) 평범한 객체인 경우: 속성만 추가 (전체 재할당 금지)
config.headers = config.headers ?? {};
(config.headers as any).Authorization = `Bearer ${token}`;
}
}
return config;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint 규칙에 any 타입을 쓰면 vercel 에서 error 를 발생하면서 배포가 막혀있습니다! axios 포함, testAuth 페이지의 any 타입을 변경해야할것 같습니다!

그리고 axios v1 + any 타입 해결책으로는 new AxiosHeaders() 인스턴스로 생성하여 통일하는 방법이 있습니다.

import axios, { AxiosInstance, AxiosHeaders, InternalAxiosRequestConfig } from 'axios';

const axiosInstance: AxiosInstance = axios.create({
  baseURL: process.env.NEXT_PUBLIC_API_URL,
  headers: new AxiosHeaders({ 'Content-Type': 'application/json' }), 
// 타입을 확정지을 수 있도록 AxiosHeaders로 초기화
});


axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {
  // SSR 방어
  if (typeof window === 'undefined') return config;

  const token = localStorage.getItem('thejulge_token');
  if (token) {
    config.headers.set('Authorization', `Bearer ${token}`);
  }

  return config;
});

참고했던 블로그도 같이 첨부드릴게요!
블로그

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 페이지 any 타입 사용으로 인해 vercel 배포가 막혀있습니다! 수정 부탁드립니다!

Comment on lines 92 to 98
const value: AuthContextValue = {
...values,
isLogin,
role,
user,
login,
logout,
signup,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후 시간이 남는다면 useMemo로 리팩토링을 해볼 수 있을것 같습니다! (제안)
isLogin, role, user 와 같은 값은 다시 계산이 일어나지 않게 할수도 있을것 같습니다!
모든 함수에 useCallback 을 넣는다면 모두다 디펜던시로 넣을 수도 있을것 같구요 !

Comment on lines 53 to 56
if (typeof window !== 'undefined') {
localStorage.setItem(TOKEN_KEY, newToken);
localStorage.setItem(USER_ID_KEY, newUserId);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 패턴이 계속 반복되고 있어서 추후 시간이 남는다면 유틸함수로 컨트롤하게 리팩토링 할 수 있을것 같습니다! (제안)

Copy link
Contributor

@sohyun0 sohyun0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저기능 만드느라 고생하셨습니다 ! 👏👏

@sohyun0 sohyun0 merged commit 5231a7a into codeit-FE18-part3:develop Oct 13, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in The-julge Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔌 api API 연동 ✨ feat 새로운 기능 추가 ♻️ refactor 결과 변화 없이 코드 구조 개선

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature] 공용 axios 인스턴스 및 Authorization 자동 첨부 구축

2 participants