-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthenticationRepositoryImpl.swift
More file actions
87 lines (77 loc) · 2.72 KB
/
Copy pathAuthenticationRepositoryImpl.swift
File metadata and controls
87 lines (77 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// AuthenticationRepositoryImpl.swift
// DevLog
//
// Created by 최윤진 on 11/2/25.
//
final class AuthenticationRepositoryImpl: AuthenticationRepository {
private let authService: AuthService
private let appleAuthService: AuthenticationService
private let githubAuthService: AuthenticationService
private let googleAuthService: AuthenticationService
private let userService: UserService
init(
authService: AuthService,
appleAuthService: AuthenticationService,
githubAuthService: AuthenticationService,
googleAuthService: AuthenticationService,
userService: UserService
) {
self.authService = authService
self.appleAuthService = appleAuthService
self.githubAuthService = githubAuthService
self.googleAuthService = googleAuthService
self.userService = userService
}
func signIn(_ provider: AuthProvider) async throws {
let response: AuthDataResponse
switch provider {
case .apple:
response = try await appleAuthService.signIn()
case .github:
response = try await githubAuthService.signIn()
case .google:
response = try await googleAuthService.signIn()
}
try await userService.upsertUser(response)
}
func signOut() async throws {
guard let uid = authService.uid,
let providerID = try await authService.getProviderID(),
let provider = AuthProvider(rawValue: providerID)
else {
throw AuthError.notAuthenticated
}
switch provider {
case .apple:
try await appleAuthService.signOut(uid)
case .github:
try await githubAuthService.signOut(uid)
case .google:
try await googleAuthService.signOut(uid)
}
}
func restore() -> Bool {
// MARK: 후에 Google API를 사용 시 Google만의 restorePreviousSignIn 로직 추가
return authService.uid != nil
}
func delete() async throws {
guard let uid = authService.uid else {
throw AuthError.notAuthenticated
}
let providers = authService.providerIDs.compactMap { AuthProvider(rawValue: $0) }
for provider in providers {
switch provider {
case .apple:
try await appleAuthService.deleteAuth(uid)
case .github:
try await githubAuthService.deleteAuth(uid)
case .google:
try await googleAuthService.deleteAuth(uid)
}
}
try await authService.deleteFirestoreUserData(uid)
try await authService.deleteCurrentUser()
try await authService.clearCurrentSession()
}
}