Skip to content

Commit

Permalink
fix :: add user id to login response
Browse files Browse the repository at this point in the history
  • Loading branch information
miraexhoi committed Sep 26, 2024
1 parent 837e452 commit 06599ed
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, String role) {
public record LoginResponse(String accessToken, boolean isSignUp, String role, Long id) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,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, account.getRole().name());
writeResponse(response, accessToken, isSignUp, account.getRole().name(), account.getId());
createRefreshTokenCookie(response, refreshToken);
}

private void writeResponse(HttpServletResponse response, String accessToken, boolean isSignUp, String role) {
private void writeResponse(HttpServletResponse response, String accessToken, boolean isSignUp, String role, Long id) {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());

Expand All @@ -92,12 +92,13 @@ private void writeResponse(HttpServletResponse response, String accessToken, boo
.queryParam("accessToken", accessToken)
.queryParam("isSignUp", isSignUp)
.queryParam("role", role)
.queryParam("id", id)
.build().toUriString();

response.sendRedirect(redirectUrl);
PrintWriter writer = response.getWriter();

writer.println(objectMapper.writeValueAsString(new LoginResponse(accessToken, isSignUp, role)));
writer.println(objectMapper.writeValueAsString(new LoginResponse(accessToken, isSignUp, role, id)));
writer.flush();
} catch (IOException e) {
throw new InvalidResponseWriteException();
Expand Down

0 comments on commit 06599ed

Please sign in to comment.