Skip to content

Commit

Permalink
Merge pull request #104 from wafflestudio/feat/auth-success-userid
Browse files Browse the repository at this point in the history
Authentication success returns userid
  • Loading branch information
dennis0405 authored Jan 15, 2025
2 parents b3df127 + 2e155c6 commit f088a25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.toyTeam6Airbnb.config

import com.example.toyTeam6Airbnb.user.JwtTokenProvider
import com.example.toyTeam6Airbnb.user.controller.PrincipalDetails
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.beans.factory.annotation.Value
Expand All @@ -22,6 +23,6 @@ class CustomAuthenticationSuccessHandler(
) {
val token = jwtTokenProvider.generateToken(authentication.name)

response.sendRedirect("/redirect?token=$token")
response.sendRedirect("/redirect?token=$token&userid=${(authentication.principal as PrincipalDetails).getId()}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class UserController(
// just return the token parameter in body
@Operation(summary = "Redirect", description = "Redirect to the token", hidden = true)
@GetMapping("/redirect")
fun redirect(@RequestParam token: String): ResponseEntity<String> {
return ResponseEntity.ok(token)
fun redirect(@RequestParam token: String, @RequestParam userid: Long): ResponseEntity<RedirectResponse> {
return ResponseEntity.ok(RedirectResponse(token, userid))
}
}

Expand All @@ -53,3 +53,8 @@ data class RegisterRequest(
val showMyReviews: Boolean,
val showMyReservations: Boolean
)

data class RedirectResponse(
val token: String,
val userId: Long
)
3 changes: 3 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ spring:
client-id: ASDF
client-secret: ASDF
redirect-uri: '{baseUrl}/api/oauth2/callback/{registrationId}'
scope:
- email
- profile
naver:
client-id: ASDF
client-secret: ASDF
Expand Down

0 comments on commit f088a25

Please sign in to comment.