-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ Feature/dev 68 ] 완료 페이지로 이동 시 로그인 로직 구현 #132
Conversation
@Happhee 한 번 확인 해주셔도 됩니당!! 🙇♀️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로그인 처음인데 고생하셨습니다..! 테스트 해보면서 버그 하나씩 잡아봐야할것같네욥!
src/api/fewFetch.ts
Outdated
const accessToken = document.cookie | ||
.split('; ') | ||
.find(row => row.startsWith('accessToken=')) | ||
?.split('=')[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 쿠키 파싱하는 유틸을 따로 만들면 원하는 key 값에 대해서 value를 따로 가져오기 편할것같은데 어떻게 생각하실까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
쿠키의 키도 상수로 관리하면 편할것같습니다!
src/auth/hooks/useAuth.tsx
Outdated
if (typeof document !== 'undefined') { | ||
document.cookie = `accessToken=${accessToken}; path=/`; | ||
document.cookie = `refreshToken=${refreshToken}; path=/`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next에서 제공하는
import { setCookie } from "cookies-next";
를쓰지않고 직접 document에 접근하신이유가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅎㅎㅎㅎㅎ… 까먹었었습니다 ㅋㅋㅋㅋ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCookie, setCookie 사용하는 방향으로 리팩토링 했습니다!
src/shared/hooks/useIsLogin.tsx
Outdated
export const useIsLogin = () => { | ||
const [isLogin, setIsLogin] = useState(false); | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useEffect(function 함수명(){
이런식으로 컨벤션 맞췄어요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇 네네!! 🫡🫡
src/shared/hooks/useIsLogin.tsx
Outdated
|
||
useEffect(() => { | ||
const checkLogin = () => { | ||
if (typeof document !== 'undefined') { // 클라이언트 환경에서만 실행 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useEffect가 client 환경아니었었나욥..?그저궁금..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 저도 확인해봐야 할 것 같은데 document is not defined 에러 때문에 전체적으로 적용해놨었던 것 같네요! 저 부분은 클라 환경이 맞는 것 같네요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soomin9106 제가 알기론 setCookie쓰면 적용되는걸로 알고있긴합니다만..시도해보시고 말씀해주세요..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘 됩니닷!! 👍
간단하게 리팩토링 완료 했습니다! |
🔥 Related Issues
https://linear.app/fewletter/issue/DEV-68/%EC%99%84%EB%A3%8C-%ED%8E%98%EC%9D%B4%EC%A7%80%EB%A1%9C-%EC%9D%B4%EB%8F%99-%EC%8B%9C-%EB%A1%9C%EA%B7%B8%EC%9D%B8-%EB%A1%9C%EC%A7%81-%EA%B5%AC%ED%98%84
💜 작업 내용
onRequest => cookie 에 있는 accessToken 확인 + 헤더에 넣어주기
onResponse => 401 일 경우 refreshToken 통신 하는 로직
/auth/validation/complete?auth_token=~
페이지로 진입 시 useAuth 훅을 통해 로그인 ( 혹은 회원가입 후 로그인) 수행😡 Trouble Shooting
Screenshot 📷
Reference 📚