From 7003f64381b43af6b8d77b9456527d27113a9dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=B8=EB=9E=98?= Date: Wed, 25 Sep 2024 22:56:20 +0900 Subject: [PATCH] refactor :: add role value to login response --- .../spaced/global/security/dto/response/LoginResponse.java | 2 +- .../global/security/handler/OAuth2SuccessHandler.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/dnd/spaced/global/security/dto/response/LoginResponse.java b/src/main/java/com/dnd/spaced/global/security/dto/response/LoginResponse.java index 5719e59f..5179deb5 100644 --- a/src/main/java/com/dnd/spaced/global/security/dto/response/LoginResponse.java +++ b/src/main/java/com/dnd/spaced/global/security/dto/response/LoginResponse.java @@ -1,4 +1,4 @@ package com.dnd.spaced.global.security.dto.response; -public record LoginResponse(String accessToken, boolean isSignUp) { +public record LoginResponse(String accessToken, boolean isSignUp, String role) { } diff --git a/src/main/java/com/dnd/spaced/global/security/handler/OAuth2SuccessHandler.java b/src/main/java/com/dnd/spaced/global/security/handler/OAuth2SuccessHandler.java index c7140204..ca83c71e 100644 --- a/src/main/java/com/dnd/spaced/global/security/handler/OAuth2SuccessHandler.java +++ b/src/main/java/com/dnd/spaced/global/security/handler/OAuth2SuccessHandler.java @@ -77,11 +77,11 @@ private void login(HttpServletResponse response, Account account, boolean isSign String accessToken = tokenEncoder.encode(LocalDateTime.now(), TokenType.ACCESS, claims); String refreshToken = tokenEncoder.encode(LocalDateTime.now(), TokenType.REFRESH, claims); - writeResponse(response, accessToken, isSignUp); + writeResponse(response, accessToken, isSignUp, account.getRole().name()); createRefreshTokenCookie(response, refreshToken); } - private void writeResponse(HttpServletResponse response, String accessToken, boolean isSignUp) { + private void writeResponse(HttpServletResponse response, String accessToken, boolean isSignUp, String role) { response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); @@ -89,12 +89,13 @@ private void writeResponse(HttpServletResponse response, String accessToken, boo String redirectUrl = UriComponentsBuilder.fromUriString("http://localhost:3000/google/callback/loading") .queryParam("accessToken", accessToken) .queryParam("isSignUp", isSignUp) + .queryParam("role", role) .build().toUriString(); response.sendRedirect(redirectUrl); PrintWriter writer = response.getWriter(); - writer.println(objectMapper.writeValueAsString(new LoginResponse(accessToken, isSignUp))); + writer.println(objectMapper.writeValueAsString(new LoginResponse(accessToken, isSignUp, role))); writer.flush(); } catch (IOException e) { throw new InvalidResponseWriteException();