feat(local): 관리자 개발자 로그인(dev-login) + 관리자 시드 분리
- DevAuthController: @Profile("local") 전용 /api/auth/dev-login (이메일로 세션 발급) — 관리자 콘솔 로컬 확인용
- AdminSeedData: admin@dog.com(ADMIN) + 더미 회원 시드. 앱 시드(LocalSeedData)와 분리, @Order로 선실행
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.dog.dognation.config;
|
||||
|
||||
import com.dog.dognation.auth.dto.LoginResponse;
|
||||
import com.dog.dognation.auth.dto.MemberResponse;
|
||||
import com.dog.dognation.common.exception.ApiException;
|
||||
import com.dog.dognation.domain.auth.AuthSession;
|
||||
import com.dog.dognation.domain.auth.AuthSessionRepository;
|
||||
import com.dog.dognation.domain.user.User;
|
||||
import com.dog.dognation.domain.user.UserRepository;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 개발자 로그인 — <b>local 프로파일 전용</b>. 구글/애플 없이 이메일로 세션을 발급한다.
|
||||
* 관리자 콘솔을 로컬에서 확인하기 위한 용도(예: admin@dog.com). 운영 빌드에는 등록되지 않는다.
|
||||
*/
|
||||
@Profile("local")
|
||||
@RestController
|
||||
@RequestMapping("/api/auth")
|
||||
public class DevAuthController {
|
||||
|
||||
private static final Duration TTL = Duration.ofDays(30);
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final AuthSessionRepository sessionRepository;
|
||||
|
||||
public DevAuthController(UserRepository userRepository, AuthSessionRepository sessionRepository) {
|
||||
this.userRepository = userRepository;
|
||||
this.sessionRepository = sessionRepository;
|
||||
}
|
||||
|
||||
/** 이메일로 세션 발급 (검증 없음, local 전용). */
|
||||
@PostMapping("/dev-login")
|
||||
@Transactional
|
||||
public LoginResponse devLogin(@RequestBody Map<String, String> body) {
|
||||
String email = body.get("email");
|
||||
if (email == null || email.isBlank()) {
|
||||
throw new ApiException(HttpStatus.BAD_REQUEST, "email 이 필요합니다.");
|
||||
}
|
||||
User user = userRepository.findByEmail(email)
|
||||
.orElseThrow(() -> new ApiException(HttpStatus.NOT_FOUND, "회원을 찾을 수 없습니다: " + email));
|
||||
|
||||
String token = UUID.randomUUID().toString().replace("-", "");
|
||||
sessionRepository.save(AuthSession.issue(token, user, true, OffsetDateTime.now().plus(TTL)));
|
||||
return new LoginResponse(token, TTL.getSeconds(), MemberResponse.from(user));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user