Skip to content

Commit

Permalink
✨ added oauth2 social login funcitons to extract username and email f…
Browse files Browse the repository at this point in the history
…rom social login and create new user in database
  • Loading branch information
jafacode committed Jan 6, 2025
1 parent 454ec92 commit 9d8e3aa
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class SocialLoginUserService(private val userService: UserService) : OAuth2UserS

// Extract attributes
val provider = userRequest.clientRegistration.registrationId
val email = oauth2User.getAttribute<String>("email") ?: throw OAuth2AuthenticationException
val providerId = oauth2User.getAttribute<String>("sub") ?: throw OAuth2AuthenticationException("Provider ID not found in attributes")
val name = oauth2User.getAttribute<String>("name") ?: throw OAuth2AuthenticationException("Name not found in attributes")
val email = oauth2User.getAttribute<String>("email") ?: throw OAuth2AuthenticationException()
val providerId = oauth2User.getAttribute<String>("sub") ?: throw OAuth2AuthenticationException()
val name = oauth2User.getAttribute<String>("name") ?: throw OAuth2AuthenticationException()

// Create or retrieve the user
return userService.createOrRetrieveSocialUser(email, providerId, provider, name)
userService.createOrRetrieveSocialUser(email, providerId, provider, name)
return oauth2User
}
}

0 comments on commit 9d8e3aa

Please sign in to comment.