Skip to content

Commit 4f8f6d4

Browse files
committed
refactor: 로그인 도메인에 따라 분기 및 커스텀 에러 추가
1 parent 64f6280 commit 4f8f6d4

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

DevLog/Infra/Common/InfraLayerError.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// Created by opfic on 3/11/26.
66
//
77

8+
import AuthenticationServices
89
import Foundation
10+
import GoogleSignIn
911

1012
enum FirestoreError: Error, LocalizedError {
1113
case dataNotFound(_ key: String)
@@ -26,3 +28,27 @@ enum EmailFetchError: Error, Equatable {
2628
case emailNotFound
2729
case emailMismatch
2830
}
31+
32+
enum SocialLoginError: Error {
33+
case invalidOAuthState
34+
case failedToStartWebAuthenticationSession
35+
}
36+
37+
extension Error {
38+
var isSocialLoginCancelled: Bool {
39+
// Apple 로그인 취소
40+
if let authorizationError = self as? ASAuthorizationError {
41+
return authorizationError.code == .canceled
42+
}
43+
44+
// Github 로그인 취소
45+
if let webAuthenticationSessionError = self as? ASWebAuthenticationSessionError {
46+
return webAuthenticationSessionError.code == .canceledLogin
47+
}
48+
49+
let error = self as NSError
50+
// Google 로그인 취소
51+
return error.domain == kGIDSignInErrorDomain
52+
&& error.code == GIDSignInError.canceled.rawValue
53+
}
54+
}

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
}

0 commit comments

Comments
 (0)