Skip to content

Commit

Permalink
Merge :: OAuth 도메인 Apple Auth Service (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
seu1a authored Oct 14, 2024
2 parents 4638aea + 0b92838 commit a3d234d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,4 @@ class AppleCodeRequest (
@JsonSetter(nulls = Nulls.AS_EMPTY)
val name: String = "",

@JsonProperty("email")
@JsonSetter(nulls = Nulls.AS_EMPTY)
val email: String = ""

) {

fun isNameAndEmailEmpty(): Boolean {
return name.isEmpty() && email.isEmpty()
}

}
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AppleAuthService (
private val saveMemberPort: SaveMemberPort,
private val saveOAuthPort: SaveOAuthPort,
private val loadMemberPort: LoadMemberPort,
private val loadOAuthPort: LoadOAuthPort
): AppleAuthUseCase {

override fun authenticate(dto: AppleCodeRequest): BaseResponse<JwtInfo> {
Expand All @@ -39,22 +38,10 @@ class AppleAuthService (
val publicKey = appleUtils.generate(headers, keys)
val claims = appleUtils.extractClaims(exchange.idToken, publicKey)

if (dto.isNameAndEmailEmpty()) {
val sub = claims.subject
val oauth = loadOAuthPort.loadOAuthByProviderAndSub(Provider.APPLE, sub)
val member = loadMemberPort.loadMemberWithId(oauth.member.id!!.value)
val email = claims["email"] as String

member.addFCMToken(dto.token)
saveMemberPort.saveMember(member)

return BaseResponse(
message = "애플 로그인 성공 !!",
data = jwtUtils.generate(member)
)
}

if (!existMemberPort.existMemberWithEmail(dto.email)) {
val model = Member(dto.name, dto.token, dto.email)
if (!existMemberPort.existMemberWithEmail(email)) {
val model = Member(dto.name, dto.token, email)
val member = saveMemberPort.saveMember(model)

val oauth = OAuth(
Expand All @@ -72,6 +59,13 @@ class AppleAuthService (
)
}

throw CustomException(OAuthErrorCode.OAUTH_NOT_SUFFICIENT)
val member = loadMemberPort.loadMemberWithEmail(email)
member.addFCMToken(dto.token)
saveMemberPort.saveMember(member)

return BaseResponse(
message = "애플 로그인 성공 !!",
data = jwtUtils.generate(member)
)
}
}

0 comments on commit a3d234d

Please sign in to comment.