Skip to content

Commit

Permalink
fix: 500 When try login with SSO
Browse files Browse the repository at this point in the history
  • Loading branch information
STALEMATE02 committed Feb 17, 2025
1 parent 84b093a commit a62aa38
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
6 changes: 4 additions & 2 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ services:
- .database.env
redis:
image: redis:7.4.1
frontend:
image: jiseong5036/casper-frontend:latest

phpmyadmin:
image: phpmyadmin
restart: always
ports:
- "3000:3000"
- 8000:80
environment:
- PMA_ARBITRARY=1

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ArticleApiController {
private AccountLockService accountLockService;

@GetMapping("/album/{page}")
@Operation(summary = "앨범 조회", description = "얼범을 조회합니다.")
@Operation(summary = "앨범 조회", description = "앨범을 조회합니다.")
public ResponseEntity<?> album(@Parameter(description = "게시판 페이지") @PathVariable Long page) {
if (page == null || page <= 1) page = 1L;
page = (page - 1) * 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ public interface UserRepository extends JpaRepository<UserEntity, String> {

@Query(value = "SELECT * FROM userEntity WHERE email = :email", nativeQuery = true)
UserEntity findByEmail(@Param("email") String email);

@Query(value = "SELECT * FROM userEntity WHERE name = :name", nativeQuery = true)
UserEntity findByName(@Param("name") String name);
}
8 changes: 7 additions & 1 deletion src/main/java/com/example/newsper/service/OAuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,17 @@ public UserEntity sso(String code, String redirectUri) {
log.info("AccessToken = " + accessToken);
JsonNode userResourceNode = getSsoUserResource(accessToken);

String id = userResourceNode.get("id").asText();
String id = userResourceNode.get("nickname").asText();
String email = userResourceNode.get("email").asText();
String name = userResourceNode.get("name").asText();
log.info("email = " + email);

if (userService.findByName(name) != null) {
UserEntity entity = userService.findByName(name);
entity.setEmail(email);
userService.modify(entity);
}

if (userService.findByEmail(email) == null) {
UserDto dto = new UserDto(email, id + email, email, name, email, null, null, null, "associate");
return userService.newUser(dto);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/example/newsper/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public UserEntity findByEmail(String email) {
return userRepository.findByEmail(email);
}

public UserEntity findByName(String name) {
return userRepository.findByName(name);
}

public Map<String, Object> showall(UserRole role) {
List<UserEntity> users = userRepository.findAll();
List<Map<String, Object>> userList = new ArrayList<>();
Expand Down

0 comments on commit a62aa38

Please sign in to comment.