Skip to content

Commit 3bcfdde

Browse files
committed
refactor: Sendable 경고를 해결하기 위한 잔여 구현물 제거
1 parent 092b538 commit 3bcfdde

10 files changed

Lines changed: 64 additions & 233 deletions

File tree

Application/DevLogInfra/Sources/Common/FirebaseDependency.swift

Lines changed: 0 additions & 47 deletions
This file was deleted.

Application/DevLogInfra/Sources/Service/AuthServiceImpl.swift

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import DevLogCore
1313
import DevLogData
1414

1515
final class AuthServiceImpl: AuthService {
16-
private let store = FirebaseDependency(value: Firestore.firestore())
17-
private let messaging = FirebaseDependency(value: Messaging.messaging())
16+
private let store = Firestore.firestore()
17+
private let messaging = Messaging.messaging()
1818
private let logger = Logger(category: "AuthServiceImpl")
19-
private let authStatePublisher: AuthStatePublisher
19+
private let subject = CurrentValueSubject<Bool, Never>(Auth.auth().currentUser != nil)
20+
private var handler: AuthStateDidChangeListenerHandle?
21+
private var isCompletingSignIn = false
2022

2123
var uid: String? {
2224
Auth.auth().currentUser?.uid
@@ -35,26 +37,36 @@ final class AuthServiceImpl: AuthService {
3537
}
3638

3739
init() {
38-
authStatePublisher = AuthStatePublisher(logger: logger)
40+
handler = Auth.auth().addStateDidChangeListener { [weak self] _, user in
41+
self?.handleAuthStateChange(user)
42+
}
43+
}
44+
45+
deinit {
46+
guard let handler else { return }
47+
Auth.auth().removeStateDidChangeListener(handler)
3948
}
4049

4150
func observeSignedIn() -> AnyPublisher<Bool, Never> {
42-
authStatePublisher.observeSignedIn()
51+
subject.eraseToAnyPublisher()
4352
}
4453

4554
func beginSignIn() {
4655
logger.info("Beginning sign-in bootstrap")
47-
authStatePublisher.beginSignIn()
56+
isCompletingSignIn = true
57+
subject.send(false)
4858
}
4959

5060
func completeSignIn() {
5161
logger.info("Completing sign-in bootstrap")
52-
authStatePublisher.completeSignIn()
62+
isCompletingSignIn = false
63+
subject.send(Auth.auth().currentUser != nil)
5364
}
5465

5566
func cancelSignIn() {
5667
logger.info("Cancelling sign-in bootstrap")
57-
authStatePublisher.cancelSignIn()
68+
isCompletingSignIn = false
69+
subject.send(Auth.auth().currentUser != nil)
5870
}
5971

6072
func getProviderID() async throws -> String? {
@@ -114,59 +126,8 @@ final class AuthServiceImpl: AuthService {
114126

115127
}
116128

117-
private final class AuthStatePublisher {
118-
private let logger: Logger
119-
private let subject: CurrentValueSubject<Bool, Never>
120-
private let lock = NSLock()
121-
private var handler: FirebaseDependency<AuthStateDidChangeListenerHandle>?
122-
private var isCompletingSignIn = false
123-
124-
init(logger: Logger) {
125-
self.logger = logger
126-
self.subject = CurrentValueSubject<Bool, Never>(Auth.auth().currentUser != nil)
127-
self.handler = FirebaseDependency(
128-
value: Auth.auth().addStateDidChangeListener { [weak self] _, user in
129-
self?.handleAuthStateChange(user)
130-
}
131-
)
132-
}
133-
134-
deinit {
135-
guard let handler else { return }
136-
handler.removeAuthStateDidChangeListener()
137-
}
138-
139-
func observeSignedIn() -> AnyPublisher<Bool, Never> {
140-
lock.lock()
141-
defer { lock.unlock() }
142-
return subject.eraseToAnyPublisher()
143-
}
144-
145-
func beginSignIn() {
146-
lock.lock()
147-
isCompletingSignIn = true
148-
subject.send(false)
149-
lock.unlock()
150-
}
151-
152-
func completeSignIn() {
153-
lock.lock()
154-
isCompletingSignIn = false
155-
subject.send(Auth.auth().currentUser != nil)
156-
lock.unlock()
157-
}
158-
159-
func cancelSignIn() {
160-
lock.lock()
161-
isCompletingSignIn = false
162-
subject.send(Auth.auth().currentUser != nil)
163-
lock.unlock()
164-
}
165-
166-
private func handleAuthStateChange(_ user: User?) {
167-
lock.lock()
168-
defer { lock.unlock() }
169-
129+
private extension AuthServiceImpl {
130+
func handleAuthStateChange(_ user: User?) {
170131
let signedIn = user != nil
171132
logger.info("Firebase auth state changed. signedIn: \(signedIn)")
172133

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

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
2323
case revokeAppleAccessToken
2424
}
2525

26-
private let session = AppleSignInSession()
27-
private let store = FirebaseDependency(value: Firestore.firestore())
28-
private let functions = FirebaseDependency(value: Functions.functions(region: "asia-northeast3"))
29-
private let messaging = FirebaseDependency(value: Messaging.messaging())
26+
private var appleSignInDelegate: AppleSignInDelegate?
27+
private var appleSignInContinuation: CheckedContinuation<ASAuthorization, Error>?
28+
private let store = Firestore.firestore()
29+
private let functions = Functions.functions(region: "asia-northeast3")
30+
private let messaging = Messaging.messaging()
3031
private var user: User? { Auth.auth().currentUser }
32+
private let providerID = AuthProviderID.apple
3133
private let logger = Logger(category: "AppleAuthService")
3234

3335
func signIn() async throws -> AuthDataResponse {
@@ -79,9 +81,9 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
7981
try await changeRequest.commitChanges()
8082

8183
// FirebaseAuth 계정에 Apple ID 연결
82-
if !result.user.providerData.contains(where: { $0.providerID == AuthProviderID.apple.rawValue }) {
84+
if !result.user.providerData.contains(where: { $0.providerID == providerID.rawValue }) {
8385
let appleCredential = OAuthProvider.credential(
84-
providerID: AuthProviderID.apple,
86+
providerID: providerID,
8587
idToken: idTokenString,
8688
rawNonce: nonce
8789
)
@@ -149,7 +151,7 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
149151
}
150152

151153
let appleCredential = OAuthProvider.credential(
152-
providerID: AuthProviderID.apple,
154+
providerID: providerID,
153155
idToken: idTokenString,
154156
rawNonce: nonce
155157
)
@@ -185,7 +187,7 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
185187
}
186188

187189
logger.info("Starting Firebase Apple provider unlink. uid: \(uid)")
188-
_ = try await user?.unlink(fromProvider: AuthProviderID.apple.rawValue)
190+
_ = try await user?.unlink(fromProvider: providerID.rawValue)
189191
} catch {
190192
logger.error("Failed to unlink Apple account", error: error)
191193
throw error
@@ -195,7 +197,7 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
195197
// Apple 인증 메서드
196198
@MainActor
197199
func authenticateWithAppleAsync() async throws -> AppleAuthResponse {
198-
guard session.canStartSignIn else {
200+
guard appleSignInDelegate == nil, appleSignInContinuation == nil else {
199201
throw SocialLoginError.authenticationAlreadyInProgress
200202
}
201203

@@ -211,11 +213,13 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
211213
let controller = ASAuthorizationController(authorizationRequests: [request])
212214

213215
let authorization = try await withCheckedThrowingContinuation { continuation in
214-
let delegate = session.start(continuation: continuation) { [weak self] result in
216+
let delegate = AppleSignInDelegate { [weak self] result in
215217
self?.completeAppleSignIn(with: result)
216218
}
217-
controller.delegate = delegate
218-
controller.presentationContextProvider = delegate
219+
self.appleSignInDelegate = delegate
220+
self.appleSignInContinuation = continuation
221+
controller.delegate = self.appleSignInDelegate
222+
controller.presentationContextProvider = self.appleSignInDelegate
219223
controller.performRequests()
220224
}
221225

@@ -237,7 +241,17 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
237241

238242
@MainActor
239243
private func completeAppleSignIn(with result: Result<ASAuthorization, Error>) {
240-
session.complete(with: result)
244+
guard let continuation = appleSignInContinuation else { return }
245+
246+
appleSignInContinuation = nil
247+
appleSignInDelegate = nil
248+
249+
switch result {
250+
case .success(let authorization):
251+
continuation.resume(returning: authorization)
252+
case .failure(let error):
253+
continuation.resume(throwing: error)
254+
}
241255
}
242256

243257
// Apple CustomToken 발급 메서드
@@ -299,41 +313,3 @@ final class AppleAuthenticationServiceImpl: AuthenticationService {
299313
_ = try await revokeFunction.call(["token": token])
300314
}
301315
}
302-
303-
private final class AppleSignInSession {
304-
@MainActor
305-
private var delegate: AppleSignInDelegate?
306-
@MainActor
307-
private var continuation: CheckedContinuation<ASAuthorization, Error>?
308-
309-
@MainActor
310-
var canStartSignIn: Bool {
311-
delegate == nil && continuation == nil
312-
}
313-
314-
@MainActor
315-
func start(
316-
continuation: CheckedContinuation<ASAuthorization, Error>,
317-
completion: @escaping @MainActor (Result<ASAuthorization, Error>) -> Void
318-
) -> AppleSignInDelegate {
319-
let delegate = AppleSignInDelegate(finish: completion)
320-
self.delegate = delegate
321-
self.continuation = continuation
322-
return delegate
323-
}
324-
325-
@MainActor
326-
func complete(with result: Result<ASAuthorization, Error>) {
327-
guard let continuation else { return }
328-
329-
self.continuation = nil
330-
self.delegate = nil
331-
332-
switch result {
333-
case .success(let authorization):
334-
continuation.resume(returning: authorization)
335-
case .failure(let error):
336-
continuation.resume(throwing: error)
337-
}
338-
}
339-
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ final class GithubAuthenticationServiceImpl: NSObject, AuthenticationService {
2626
static let acceptHeader = "application/vnd.github.v3+json"
2727
}
2828

29-
private let store = FirebaseDependency(value: Firestore.firestore())
30-
private let functions = FirebaseDependency(value: Functions.functions(region: "asia-northeast3"))
31-
private let messaging = FirebaseDependency(value: Messaging.messaging())
29+
private let store = Firestore.firestore()
30+
private let functions = Functions.functions(region: "asia-northeast3")
31+
private let messaging = Messaging.messaging()
3232
private var user: User? { Auth.auth().currentUser }
33+
private let providerID = AuthProviderID.gitHub
3334
private let provider = TopViewControllerProvider()
3435
private let logger = Logger(category: "GithubAuthService")
3536
private let gitHubApiClient = NXAPIClient(
@@ -66,8 +67,8 @@ final class GithubAuthenticationServiceImpl: NSObject, AuthenticationService {
6667
}
6768

6869
// 5. GitHub 계정과 Firebase Auth 계정 연결
69-
if !result.user.providerData.contains(where: { $0.providerID == "github.com" }) {
70-
let credential = OAuthProvider.credential(providerID: AuthProviderID.gitHub, accessToken: accessToken)
70+
if !result.user.providerData.contains(where: { $0.providerID == providerID.rawValue }) {
71+
let credential = OAuthProvider.credential(providerID: providerID, accessToken: accessToken)
7172
try await result.user.link(with: credential)
7273
}
7374

@@ -136,7 +137,7 @@ final class GithubAuthenticationServiceImpl: NSObject, AuthenticationService {
136137

137138
try await tokensRef.setData(["githubAccessToken": accessToken], merge: true)
138139

139-
let credential = OAuthProvider.credential(providerID: AuthProviderID.gitHub, accessToken: accessToken)
140+
let credential = OAuthProvider.credential(providerID: providerID, accessToken: accessToken)
140141
try await user?.link(with: credential)
141142

142143
logger.info("Successfully linked GitHub account")
@@ -160,7 +161,7 @@ final class GithubAuthenticationServiceImpl: NSObject, AuthenticationService {
160161
try await tokensRef.updateData(["githubAccessToken": FieldValue.delete()])
161162

162163
logger.info("Starting Firebase GitHub provider unlink. uid: \(uid)")
163-
_ = try await user?.unlink(fromProvider: AuthProviderID.gitHub.rawValue)
164+
_ = try await user?.unlink(fromProvider: providerID.rawValue)
164165
} catch {
165166
logger.error("Failed to unlink GitHub account", error: error)
166167
throw error

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import DevLogCore
1414
import DevLogData
1515

1616
final class GoogleAuthenticationServiceImpl: AuthenticationService {
17-
private let store = FirebaseDependency(value: Firestore.firestore())
18-
private let messaging = FirebaseDependency(value: Messaging.messaging())
17+
private let store = Firestore.firestore()
18+
private let messaging = Messaging.messaging()
1919
private var user: User? { Auth.auth().currentUser }
2020
private let provider = TopViewControllerProvider()
2121
private let logger = Logger(category: "GoogleAuthService")

Application/DevLogInfra/Sources/Service/UserServiceImpl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import DevLogCore
1111
import DevLogData
1212

1313
final class UserServiceImpl: UserService {
14-
private let store = FirebaseDependency(value: Firestore.firestore())
14+
private let store = Firestore.firestore()
1515
private let logger = Logger(category: "UserServiceImpl")
1616

1717
// 유저를 Firestore에 저장 및 업데이트

Application/DevLogPersistence/Sources/Widget/UserDefaultsDependency.swift

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)