Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
[BE] fix: 로그인 오류 수정 (#434)
Browse files Browse the repository at this point in the history
fix: 로그인 오류 수정
  • Loading branch information
cheon-eunjeong authored and Eun-chan Cho committed Sep 22, 2023
1 parent 7ed0d74 commit b5a499c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.donggle.backend.application.repository.MemberCredentialsRepository;
import org.donggle.backend.application.repository.MemberRepository;
import org.donggle.backend.application.repository.TokenRepository;
import org.donggle.backend.application.repository.dto.MemberInfo;
import org.donggle.backend.domain.auth.JwtTokenProvider;
import org.donggle.backend.domain.auth.RefreshToken;
import org.donggle.backend.domain.category.Category;
Expand All @@ -19,6 +20,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@Transactional
@RequiredArgsConstructor
Expand All @@ -31,10 +34,13 @@ public class AuthService {


public TokenResponse login(final SocialUserInfo socialUserInfo) {
return memberRepository.findBySocialId(socialUserInfo.socialId())
.map(memberInfo -> new Member(memberInfo.id(), new MemberName(socialUserInfo.nickname()), memberInfo.socialId()))
.map(this::createTokens)
.orElse(createTokens(initializeMember(socialUserInfo)));
final Optional<MemberInfo> optionalMemberInfo = memberRepository.findBySocialId(socialUserInfo.socialId());
if (optionalMemberInfo.isPresent()) {
final MemberInfo memberInfo = optionalMemberInfo.get();
final Member member = new Member(memberInfo.id(), new MemberName(socialUserInfo.nickname()), memberInfo.socialId());
return createTokens(member);
}
return createTokens(initializeMember(socialUserInfo));
}

public void logout(final Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public TrashResponse findTrashedWritingList(final Long memberId) {
public void trashWritings(final Long memberId, final List<Long> writingIds) {
writingIds.stream()
.map(writingId -> {
final Writing findWriting = writingRepository.findById(writingId)
final Writing findWriting = writingRepository.findByMemberIdAndWritingIdAndStatusIsNotDeleted(memberId, writingId)
.orElseThrow(() -> new DeleteWritingNotFoundException(writingId));
validateAuthorization(memberId, findWriting);
return findWriting;
Expand Down

0 comments on commit b5a499c

Please sign in to comment.