Skip to content

Commit

Permalink
Merge pull request #164 from dnd-side-project/refactor/#163
Browse files Browse the repository at this point in the history
Add role value to login response
  • Loading branch information
miraexhoi authored Sep 25, 2024
2 parents dc1d4ec + 7003f64 commit 5a5a6db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,25 @@ 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());

try {
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();
Expand Down

0 comments on commit 5a5a6db

Please sign in to comment.