Skip to content
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

[FEAT] 로그인 구현 #22

Merged
merged 18 commits into from
Oct 1, 2023
Merged

[FEAT] 로그인 구현 #22

merged 18 commits into from
Oct 1, 2023

Conversation

kssumin
Copy link
Contributor

@kssumin kssumin commented Oct 1, 2023

어떤 내용에 대한 PR인가요?

로그인 구현

변경 사항

11조의 JWT 토큰 인증 절차는 다음과 같습니다.

[FE] 이메일과 비밀번호를 준다.
[BE] 이메일 비밀번호를 검증하고, 만료시간이 설정된 AccessToken 및 RefreshToken과 함께 AccessToken의 만료시간에 대한 정보까지 반환해준다. 이 때 반환해주는 RefreshToken의 정보는 DB에 { ID, RefreshToken }으로 저장해둔다.
[FE] 서버에게 받은 AccessToken 정보로 요청을 할 때마다 미리 AccessToken의 만료 기간을 확인한다. 이때 만료 시간이 30초 이내(시간은 알아서 설정)로 남았으면 API 요청 대신 RefreshToken을 활용한 재발급 요청을 보낸다.
[BE] 재발급 요청을 받으면 전달받은 RefreshToken의 정보가 DB에 있는 정보와 동일한지 확인한뒤 새로운 AccessToken과 AccessToken의 만료 시간을 함께 반환한다. API 요청이 오면 요청받은 데이터를 보내준다.
[FE] 새로운 AccessToken이 반환되면 만료기간을 기억해두고, 다음 요청 전에 다시 AccessToken의 만료 시간을 확인하여 요청을 진행한다.

무엇을 위주로 보면 좋을까요?

리뷰어가 어디를 집중적으로 보면 좋을 지 알려주세요!

관련된 이슈

closes (#19)

테스트 방법

변경 사항에 대한 테스트 방법이나 확인 사항을 기술합니다.

@kssumin kssumin self-assigned this Oct 1, 2023
@kssumin kssumin merged commit 99d470b into weekly Oct 1, 2023
0 of 2 checks passed
@kssumin kssumin deleted the feat/#19/login branch October 1, 2023 15:16

private void validPassword(final String requestPassword, final UserEntity userEntity) {
if (!matchPassword(requestPassword, userEntity.getPassword())) {
throw new NotFoundException("존재하지 않는 비밀번호입니다");
Copy link
Contributor

Choose a reason for hiding this comment

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

좀 마이너한데 메세지명을 로그인스럽게 바꿔보는건 어떨까요?
ex) "로그인에 실패했습니다." 등등

import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<UserEntity, Long> {
boolean existsByEmail(String email);

boolean existsByNickname(String nickname);

Optional<UserEntity> findByEmail(String email);
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional<>로 한 이유가 궁금합니다!


@Service
@RequiredArgsConstructor
public class TokenService {
Copy link
Contributor

Choose a reason for hiding this comment

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

login service에서 tokenservice.excute를 했을 때 어떤 서비스일지 고민했기 때문에 이름을 구체적으로 바꾸는게 좋을 거 같습니다

}
}

public Date getExpiredDate(final String token) {
Copy link
Contributor

Choose a reason for hiding this comment

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

로컬 데이트 타임이 낫지 않나요?


@RestController
@RequiredArgsConstructor
@RequestMapping("/api/auth")
Copy link
Contributor

Choose a reason for hiding this comment

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

이거 앞부분에 api쓰는거 나중에 배포할때 전부 다 그렇게 바꿀 때를 대비해서 한건가요?

.httpOnly(true)
.build();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

재발급하는 api는 따로 없나?

Copy link
Contributor

@jinwooseok jinwooseok Oct 7, 2023

Choose a reason for hiding this comment

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

유저닉네임이 필요한데 외래키로 이뤄진 관계가 아니라서 join을 해서 가져올수가 없어서 findById repository가 필요합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants