Skip to content

Commit 061f365

Browse files
authored
[#245] 소셜 로그인을 취소했을 때 오류 얼럿이 뜨는 현상을 해결한다 (#248)
* chore: 에러 타입을 레이어에 따라 분리 * feat: 에러가 유저가 로그인을 취소하면 얼럿을 띄우지 않도록 구현 * refactor: 로그인 도메인에 따라 분기 및 커스텀 에러 추가 * refactor: case문 처리
1 parent ee7715e commit 061f365

7 files changed

Lines changed: 57 additions & 33 deletions

File tree

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
2-
// Error+.swift
2+
// DataLayerError.swift
33
// DevLog
44
//
5-
// Created by 최윤진 on 11/29/25.
5+
// Created by opfic on 3/11/26.
66
//
77

88
import Foundation
@@ -13,21 +13,6 @@ enum AuthError: Error {
1313
case unsupportedProvider
1414
}
1515

16-
enum FirestoreError: Error, LocalizedError {
17-
case dataNotFound(_ key: String)
18-
19-
var errorDescription: String? {
20-
switch self {
21-
case .dataNotFound(let key):
22-
return "\(key)가 Firestore에서 존재하지 않음"
23-
}
24-
}
25-
}
26-
27-
enum UIError: Error {
28-
case notFoundTopViewController
29-
}
30-
3116
enum DataError: Error {
3217
case invalidData(context: String)
3318

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// InfraLayerError.swift
3+
// DevLog
4+
//
5+
// Created by opfic on 3/11/26.
6+
//
7+
8+
import AuthenticationServices
9+
import Foundation
10+
import GoogleSignIn
11+
12+
enum FirestoreError: Error, LocalizedError {
13+
case dataNotFound(_ key: String)
14+
15+
var errorDescription: String? {
16+
switch self {
17+
case .dataNotFound(let key):
18+
return "\(key)가 Firestore에서 존재하지 않음"
19+
}
20+
}
21+
}
22+
23+
enum UIError: Error {
24+
case notFoundTopViewController
25+
}
26+
27+
enum EmailFetchError: Error, Equatable {
28+
case emailNotFound
29+
case emailMismatch
30+
}
31+
32+
enum SocialLoginError: Error {
33+
case invalidOAuthState
34+
case failedToStartWebAuthenticationSession
35+
}
36+
37+
extension Error {
38+
var isSocialLoginCancelled: Bool {
39+
switch self {
40+
// Apple 로그인 취소
41+
case let authError as ASAuthorizationError:
42+
return authError.code == .canceled
43+
// Github 로그인 취소
44+
case let webAuthError as ASWebAuthenticationSessionError:
45+
return webAuthError.code == .canceledLogin
46+
default:
47+
let nsError = self as NSError
48+
// Google 로그인 취소
49+
return nsError.domain == kGIDSignInErrorDomain && nsError.code == GIDSignInError.canceled.rawValue
50+
}
51+
}
52+
}
File renamed without changes.

DevLog/Infra/Service/SocialLogin/EmailFetchError.swift

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

DevLog/Infra/Service/SocialLogin/GithubAuthenticationService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ final class GithubAuthenticationService: NSObject, AuthenticationService {
187187
// 반환된 state 값 확인 / 받아온 값이 다르면 CSRF 공격 가능성 있음
188188
guard let returnedState = queryItems.first(where: { $0.name == "state" })?.value,
189189
returnedState == state else {
190-
continuation.resume(throwing: URLError(.userCancelledAuthentication))
190+
continuation.resume(throwing: SocialLoginError.invalidOAuthState)
191191
return
192192
}
193193

@@ -198,7 +198,7 @@ final class GithubAuthenticationService: NSObject, AuthenticationService {
198198
session.prefersEphemeralWebBrowserSession = false // 웹에서 깃헙 로그인 후 세션 유지
199199

200200
if !session.start() {
201-
continuation.resume(throwing: URLError(.userCancelledAuthentication))
201+
continuation.resume(throwing: SocialLoginError.failedToStartWebAuthenticationSession)
202202
}
203203
}
204204
}

DevLog/Presentation/ViewModel/LoginViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Combine
99
import Foundation
1010
import FirebaseAuth
11-
import GoogleSignIn
1211

1312
@Observable
1413
final class LoginViewModel: Store {
@@ -93,6 +92,7 @@ final class LoginViewModel: Store {
9392
} catch {
9493
send(.setLogined(false))
9594
sessionUseCase.execute(false)
95+
if error.isSocialLoginCancelled { return }
9696
send(.setAlert(true))
9797
}
9898
}

0 commit comments

Comments
 (0)