-
Notifications
You must be signed in to change notification settings - Fork 2
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
🎉 auth 관련 로직 및 context 제공 #37
Conversation
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.
귣! 고생하셨습니다. 배울점이 많은 코드들이였습니다 😄
apiMocking: () => | ||
process.env.NEXT_PUBLIC_API_MOCKING === 'enabled' ? 'enabled' : 'disabled', | ||
tokenName: () => process.env.NEXT_PUBLIC_API_TOKEN_NAME ?? '', |
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.
함수형식으로 하지 않고 tokenName: process.env.NEXT_PUBLIC_API_TOKEN_NAME ?? ''
으로 해도 될 것 같아요! 다른 곳에서 쓰일때 Environment.tokenName()으로 불리는 것보다 Environment.tokenName으로 하거나 getTokenName으로 바꾸는 게 좀 더 자연스러울 것 같아요 🙂
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.
원래 Env가 있는지 확인하는 함수를 감싸려해서 이렇게 해 두었는데 조금 문제가 있어서 그냥 작성해놓긴 했습니다... 다음 스프린트에서 조금 더 확인해보고 안되면 말씀처럼 하겠습니다!
import Assets from '@/config/assets' | ||
import { Environment } from '@/config/environment' | ||
|
||
//TODO: 공용 아바타 컴포넌트로 변경 |
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.
TODO 써놓는 습관 너무 좋은 것 같습니다 👍
|
||
//TODO: 공용 아바타 컴포넌트로 변경 | ||
|
||
const MenuButton = () => { |
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.
이 메뉴 버튼은 Avatar.tsx에 같이 있는 것 보다 따로 빼는게 좋을 것 같아요!
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.
그 Avatar 만드신걸로 바꿀 때 정리할 예정이라 임시로 대강 해놓았습니다. 이번 스프린트 종료되면 전체적으로 수정하겠습니다!
const AuthProvider = ({ children }: { children: React.ReactNode }) => { | ||
const { isLoggedIn, currentUser } = useValidate() | ||
|
||
const contextValue = useMemo( |
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.
useMemo를 사용해서 isLoggedIn, currentUser에 대한 반복적인 호출을 막고 최적화를 하는걸로 이해했는데 맞나요?? 🙂
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.
넵! 권장 사항으로 뜨길래 적용했습니다.
|
||
const useValidate = () => { | ||
const token = Cookies.get(Environment.tokenName()) | ||
const pathname = usePathname() |
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.
혹시 이 pathname은 어디에 쓰이는 건가요?
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.
pathname이 변할 때마다 확인하도록 useEffect dependency로 넣었습니다.
) | ||
} | ||
|
||
const useAuth = () => { |
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.
제가 잘 몰라서 그러는데 useValidate와 useAuth의 차이가 무엇인가요? 🥲
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.
useValidate로 얻은 값을 context로 공유한 것입니다
@@ -1,6 +1,7 @@ | |||
const ApiEndPoint = { | |||
kakaoLogin: () => '/oauth2/authorize/kakao/login', | |||
googleLogin: () => '/oauth2/authorize/google/login', | |||
getValidateUser: () => '/users', |
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.
이 endpoint가 페이지 이동마다 인증된 사용자인지 확인하려고 토큰을 보내는 용도인가요?? API 명세서에는 아직 따로 업데이트가 없어서 여쭤봅니다!
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.
token validate하는 api입니다!
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.
주소는 있는데 호출명이 다를거에요
- 목적
관련 티켓 번호: 78, 80
- 주요 변경 사항
기타 사항 (선택)
isLoggedIn
과 로그인 된 유저 정보를 제공하는currentUser
를useAuth()
를 통해 얻을 수 있습니다.js-cookie
라이브러리를 사용하여Cookies.get(Environment.tokenName())
을 이용해 토큰 정보를 얻거나, getValidateUser(token)을 통해 유저 정보를 사용하시면 됩니다.- 스크린샷 (선택)