-
Notifications
You must be signed in to change notification settings - Fork 7
/
AuthService.java
37 lines (31 loc) · 1.52 KB
/
AuthService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.gaebaljip.exceed.application.service.auth;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.gaebaljip.exceed.adapter.in.auth.request.LoginRequest;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.in.auth.AuthUsecase;
import com.gaebaljip.exceed.application.port.out.member.MemberPort;
import com.gaebaljip.exceed.common.dto.LoginResponseDTO;
import com.gaebaljip.exceed.common.exception.auth.PasswordMismatchException;
import com.gaebaljip.exceed.common.security.domain.JwtManager;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class AuthService implements AuthUsecase {
private final MemberPort memberPort;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
private final JwtManager jwtManager;
@Override
public LoginResponseDTO execute(LoginRequest request) {
MemberEntity member = memberPort.findCheckedMemberByEmail(request.email());
if (!bCryptPasswordEncoder.matches(request.password(), member.getPassword())) {
throw PasswordMismatchException.EXECPTION;
}
return LoginResponseDTO.builder()
.accessToken(jwtManager.generateAccessToken(member.getId()))
.refreshToken(jwtManager.generateRefreshToken(member.getId()))
.build();
}
}