-
Notifications
You must be signed in to change notification settings - Fork 2
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: Cookie 제거 및 개발용 로그인 개선 #293
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/com/listywave/auth/dev/domain/DevAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.listywave.auth.dev.domain; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
|
||
import com.listywave.user.application.domain.User; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.MapsId; | ||
import jakarta.persistence.OneToOne; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class DevAccount { | ||
|
||
@Id | ||
@Column(name = "user_id", nullable = false, unique = true) | ||
private Long id; | ||
|
||
@MapsId | ||
@OneToOne(fetch = LAZY) | ||
@JoinColumn(name = "user_id", nullable = false, unique = true) | ||
private User user; | ||
|
||
@Column(nullable = false, unique = true) | ||
private String account; | ||
|
||
@Column(nullable = false) | ||
private String password; | ||
|
||
public void validatePassword(String password) { | ||
if (this.password.equals(password)) { | ||
return; | ||
} | ||
throw new IllegalArgumentException("비밀번호가 틀렸습니다."); | ||
} | ||
|
||
public Long getUserId() { | ||
return user.getId(); | ||
} | ||
} | ||
39 changes: 39 additions & 0 deletions
39
src/main/java/com/listywave/auth/dev/presentation/DevAuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.listywave.auth.dev.presentation; | ||
|
||
import com.listywave.auth.application.domain.JwtManager; | ||
import com.listywave.auth.application.dto.LoginResponse; | ||
import com.listywave.auth.dev.domain.DevAccount; | ||
import com.listywave.auth.dev.repository.DevAccountRepository; | ||
import com.listywave.user.application.domain.User; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@Profile("!prod") | ||
@RequiredArgsConstructor | ||
public class DevAuthController { | ||
|
||
private final JwtManager jwtManager; | ||
private final DevAccountRepository devAccountRepository; | ||
|
||
@PostMapping("/login/local") | ||
ResponseEntity<LoginResponse> localLogin(@RequestBody LocalLoginRequest request) { | ||
String account = request.account(); | ||
String password = request.password(); | ||
|
||
Optional<DevAccount> optional = devAccountRepository.findByAccount(account); | ||
DevAccount devAccount = optional.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 계정입니다.")); | ||
|
||
devAccount.validatePassword(password); | ||
User user = devAccount.getUser(); | ||
String accessToken = jwtManager.createAccessToken(user.getId()); | ||
String refreshToken = jwtManager.createRefreshToken(user.getId()); | ||
LoginResponse response = LoginResponse.of(user, accessToken, refreshToken, false); | ||
return ResponseEntity.ok(response); | ||
kdkdhoho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/listywave/auth/dev/presentation/LocalLoginRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.listywave.auth.dev.presentation; | ||
|
||
public record LocalLoginRequest( | ||
String account, | ||
String password | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/listywave/auth/dev/repository/DevAccountRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.listywave.auth.dev.repository; | ||
|
||
import com.listywave.auth.dev.domain.DevAccount; | ||
import java.util.Optional; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
@Profile("!prod") | ||
public interface DevAccountRepository extends JpaRepository<DevAccount, Long> { | ||
|
||
Optional<DevAccount> findByAccount(String account); | ||
} |
85 changes: 0 additions & 85 deletions
85
src/main/java/com/listywave/auth/presentation/LocalAuthController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
오우 개발용 계정을 관리하는 테이블이 추가되는거군요
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.
개발용 DB에만 추가할 예정입니다!