-
Notifications
You must be signed in to change notification settings - Fork 0
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
Week14_멋사인 테스트 로그인 기능 구현 #13
base: main
Are you sure you want to change the base?
Conversation
const onClick = () => { | ||
const savedAccessToken = localStorage.getItem("access"); | ||
if (savedAccessToken) { | ||
router('/question'); | ||
} | ||
else { | ||
alert("로그인이 필요한 서비스입니다.") | ||
router('/login'); | ||
} | ||
}; |
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.
하등 상관 없지만
if(localStorage.getItem("access"){} 하셔도 똑같습니다!
액세스 토큰 존재 여부를 한 컴포넌트의 여러 곳에서 사용하려면 변수에 저장해서 사용하면 편하고, 이렇게 한 번만 사용 할 때는 if문 안에 바로 넣어도 괜찮아용. 상황에 맞게 잘 사용하시면 좋을 것 같습니다👍🏻👍🏻👍🏻
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.
오호 넹 참고하겠슴니다!!!
.catch((error) => { | ||
alert("토큰 기한 만료"); | ||
|
||
//토큰 기한 만료시 로그아웃 되고 로그인 페이지로 이동 | ||
localStorage.removeItem("access") | ||
localStorage.removeItem("refresh") | ||
router('/'); |
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.
경고창 이후에 로그아웃, 로그인 페이지로 이동을 한 번에 구현하셨네요👍🏻👍🏻👍🏻
과제를 이렇게 완벽하게 해주시다니🥹🥹🥹🥹🥹🥹 |
과제 완벽하게 넘넘 잘해주셨네요!!!! |
14주차 과제 완성본
14.-1.mp4
1. 로그인이 되어있는 상태라면 로그인 페이지가 아닌, 마이페이지로 이동하게 하기
로그인 된 상태(토큰)을 savedAccessToken 변수에 저장하고, useEffect 사용해서 컴포넌트가 마운트될 때 토큰을 확인하고 토큰이 존재하면 마이페이지로 라우팅하도록 함
2. 마이페이지에 로그아웃 버튼을 만들어 로그아웃 후 로그인 페이지로 이동하게 하기
handleLogout 함수를 작성하여 로그아웃 버튼을 누르면 로컬스토리지의 토큰이 삭제되고 로그인 페이지로 라우팅하도록 함
3. 리프레시 토큰도 만료되면 로그아웃 하고 로그인 페이지로 돌아가게 하기
2번과 같은 방법으로 리프레시 토큰이 만료되면 로컬스토리지의 토큰이 삭제되고 로그인 페이지로 라우팅하는 로직을 구현!
12주차 과제 멋사인 테스트에 로그인 페이지 구현
멋사인 테스트 버튼을 누르면 "로그인이 필요한 서비스입니다"라는 경고창이 뜨고, 로그인 페이지로 라우팅됨
로그인 페이지 및 회원가입 페이지 구현!
회원가입을 완료하면 "회원가입이 완료되었습니다" 경고창이 뜨고 다시 로그인 페이지로 라우팅됨
https://github.com/LikeLion-at-CAU-12th/Eunbin-Jung/assets/162856315/4e653621-60aa-4325-89d7-a1493188c108
멋사인 테스트 페이지에 로그아웃 버튼을 만들어 로그아웃 하면 토큰이 삭제되고 다시 홈 페이지로 라우팅된다!
과제 끗~~