Skip to content

Commit 745c36e

Browse files
committed
refactor: AuthService 프로토콜의 FirebaseAuth 에러 판별 제거
1 parent cad239a commit 745c36e

7 files changed

Lines changed: 23 additions & 13 deletions

File tree

Application/DevLogData/Sources/Protocol/AuthService.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ public protocol AuthService {
2121
func getProviderID() async throws -> String?
2222
func deleteCurrentUser() async throws
2323
func clearCurrentSession() async throws
24-
func isCredentialAlreadyInUseError(_ error: Error) -> Bool
2524
}

Application/DevLogData/Sources/Repository/AuthDataRepositoryImpl.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ private extension AuthDataRepositoryImpl {
9494
}
9595
}
9696

97-
if authService.isCredentialAlreadyInUseError(error) {
98-
return AuthError.linkCredentialAlreadyInUse
99-
}
100-
10197
return error
10298
}
10399
}

Application/DevLogInfra/Sources/Extension/FirebaseAuthUser+.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ extension FirebaseAuth.User {
2626
)
2727
}
2828
}
29+
30+
extension Error {
31+
var isFirebaseCredentialAlreadyInUse: Bool {
32+
let nsError = self as NSError
33+
guard nsError.domain == AuthErrorDomain,
34+
let authErrorCode = AuthErrorCode(rawValue: nsError.code) else {
35+
return false
36+
}
37+
return authErrorCode == .credentialAlreadyInUse
38+
}
39+
}

Application/DevLogInfra/Sources/Service/AuthServiceImpl.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,4 @@ final class AuthServiceImpl: AuthService {
134134
}
135135
}
136136

137-
func isCredentialAlreadyInUseError(_ error: Error) -> Bool {
138-
let nsError = error as NSError
139-
guard nsError.domain == AuthErrorDomain,
140-
let authErrorCode = AuthErrorCode(rawValue: nsError.code) else {
141-
return false
142-
}
143-
return authErrorCode == .credentialAlreadyInUse
144-
}
145137
}

Application/DevLogInfra/Sources/Service/SocialLogin/AppleAuthenticationServiceImpl.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import FirebaseMessaging
1414
import Foundation
1515
import DevLogCore
1616
import DevLogData
17+
import DevLogDomain
1718

1819
final class AppleAuthenticationServiceImpl: AuthenticationService {
1920
private enum FunctionName: String {
@@ -159,6 +160,9 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
159160
try await user?.link(with: appleCredential)
160161
} catch {
161162
logger.error("Failed to link Apple account", error: error)
163+
if error.isFirebaseCredentialAlreadyInUse {
164+
throw AuthError.linkCredentialAlreadyInUse
165+
}
162166
throw error
163167
}
164168
}

Application/DevLogInfra/Sources/Service/SocialLogin/GithubAuthenticationServiceImpl.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import FirebaseMessaging
1414
import Nexa
1515
import DevLogCore
1616
import DevLogData
17+
import DevLogDomain
1718

1819
final class GithubAuthenticationServiceImpl: NSObject, AuthenticationService {
1920
private enum FunctionName: String {
@@ -143,6 +144,9 @@ final class GithubAuthenticationServiceImpl: NSObject, AuthenticationService {
143144
logger.info("Successfully linked GitHub account")
144145
} catch {
145146
logger.error("Failed to link GitHub account", error: error)
147+
if error.isFirebaseCredentialAlreadyInUse {
148+
throw AuthError.linkCredentialAlreadyInUse
149+
}
146150
throw error
147151
}
148152
}

Application/DevLogInfra/Sources/Service/SocialLogin/GoogleAuthenticationServiceImpl.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Foundation
1212
import GoogleSignIn
1313
import DevLogCore
1414
import DevLogData
15+
import DevLogDomain
1516

1617
final class GoogleAuthenticationServiceImpl: AuthenticationService {
1718
private let store = Firestore.firestore()
@@ -123,6 +124,9 @@ final class GoogleAuthenticationServiceImpl: AuthenticationService {
123124
try await user?.link(with: credential)
124125
} catch {
125126
logger.error("Failed to link Google account", error: error)
127+
if error.isFirebaseCredentialAlreadyInUse {
128+
throw AuthError.linkCredentialAlreadyInUse
129+
}
126130
throw error
127131
}
128132
}

0 commit comments

Comments
 (0)