From f371c956c3ecc9a895b928ef0e0ddd4744068e70 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Mon, 5 May 2025 15:49:58 +0900 Subject: [PATCH 01/22] =?UTF-8?q?[#28]=20AuthRepository=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/Repositories/AuthRepositoryImpl.swift | 17 +++++++++++++++++ .../Domain/Interfaces/AuthRepository.swift | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift create mode 100644 Mark-In/Sources/Domain/Interfaces/AuthRepository.swift diff --git a/Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift b/Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift new file mode 100644 index 0000000..42d7080 --- /dev/null +++ b/Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift @@ -0,0 +1,17 @@ +// +// AuthRepositoryImpl.swift +// Mark-In +// +// Created by 이정동 on 5/5/25. +// + +import Foundation + +import FirebaseAuth + +struct AuthRepositoryImpl: AuthRepository { + func fetchCurrentUserID() -> String? { + let user = Auth.auth().currentUser + return user?.uid + } +} diff --git a/Mark-In/Sources/Domain/Interfaces/AuthRepository.swift b/Mark-In/Sources/Domain/Interfaces/AuthRepository.swift new file mode 100644 index 0000000..9a4acda --- /dev/null +++ b/Mark-In/Sources/Domain/Interfaces/AuthRepository.swift @@ -0,0 +1,12 @@ +// +// AuthRepository.swift +// Mark-In +// +// Created by 이정동 on 5/5/25. +// + +import Foundation + +protocol AuthRepository { + func fetchCurrentUserID() -> String? +} From 49f05ff547801c8188dc5e8cb7949fbd66abee79 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Mon, 5 May 2025 15:51:25 +0900 Subject: [PATCH 02/22] =?UTF-8?q?[#28]=20FetchCurrentUserIDUseCase=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FetchCurrentUserIDUseCaseImpl.swift | 21 +++++++++++++++++++ .../FetchCurrentUserIDUseCase.swift | 12 +++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift create mode 100644 Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift diff --git a/Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift b/Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift new file mode 100644 index 0000000..9266447 --- /dev/null +++ b/Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift @@ -0,0 +1,21 @@ +// +// FetchCurrentUserIDUseCaseImpl.swift +// Mark-In +// +// Created by 이정동 on 5/5/25. +// + +import Foundation + +struct FetchCurrentUserIDUseCaseImpl: FetchCurrentUserIDUseCase { + + private let authRepository: AuthRepository + + init(authRepository: AuthRepository) { + self.authRepository = authRepository + } + + func execute() -> String? { + authRepository.fetchCurrentUserID() + } +} diff --git a/Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift b/Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift new file mode 100644 index 0000000..59c6e33 --- /dev/null +++ b/Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift @@ -0,0 +1,12 @@ +// +// FetchCurrentUserIDUseCase.swift +// Mark-In +// +// Created by 이정동 on 5/5/25. +// + +import Foundation + +protocol FetchCurrentUserIDUseCase { + func execute() -> String? +} From f7b05055220348932b046afc796fdf8e239c27ee Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Mon, 5 May 2025 16:04:28 +0900 Subject: [PATCH 03/22] =?UTF-8?q?[#28]=20DIContainer=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/DIContainer.swift | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Mark-In/Sources/App/DIContainer.swift diff --git a/Mark-In/Sources/App/DIContainer.swift b/Mark-In/Sources/App/DIContainer.swift new file mode 100644 index 0000000..20ceaa7 --- /dev/null +++ b/Mark-In/Sources/App/DIContainer.swift @@ -0,0 +1,61 @@ +// +// DIContainer.swift +// Mark-In +// +// Created by 이정동 on 5/5/25. +// + +import Foundation + +// TODO: 코어 모듈로 이전 +final class DIContainer { + static let shared = DIContainer() + private var dependencies: [String: Any] = [:] + + private init() {} + + func register(_ dependency: T) { + let key = String(describing: T.self) + dependencies[key] = dependency + } + + func resolve() -> T { + let key = String(describing: T.self) + let dependency = dependencies[key] + + guard let dependency = dependency as? T else { + fatalError("\(key)는 register되지 않았어어요. resolve 부르기전에 register 해주세요") + } + + return dependency + } +} + +// TODO: Core 모듈 or Feature(공통) 모듈 중 어느 곳이 적합한지 고민 +@Observable +final class AppState { + var isLoginned: Bool = false +} + +extension DIContainer { + func registerDependencies() { + /// AppState + let appState = AppState() + + register(appState) + + /// Repository + let authRepository = AuthRepositoryImpl() + let folderRepository = FolderRepositoryImpl() + let linkRepository = LinkRepositoryImpl() + + register(authRepository as AuthRepository) + register(folderRepository as FolderRepository) + register(linkRepository as LinkRepository) + + /// UseCase + let fetchCurrentUserIDUseCase = FetchCurrentUserIDUseCaseImpl(authRepository: authRepository) + + register(fetchCurrentUserIDUseCase as FetchCurrentUserIDUseCase) + } +} From ac2ea8add6fafb30b3f417693654f585f23f3de9 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Mon, 5 May 2025 16:09:42 +0900 Subject: [PATCH 04/22] =?UTF-8?q?[#28]=20RootViewModel=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/RootViewModel.swift | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Mark-In/Sources/App/RootViewModel.swift diff --git a/Mark-In/Sources/App/RootViewModel.swift b/Mark-In/Sources/App/RootViewModel.swift new file mode 100644 index 0000000..d2b3c63 --- /dev/null +++ b/Mark-In/Sources/App/RootViewModel.swift @@ -0,0 +1,56 @@ +// +// RootViewModel.swift +// Mark-In +// +// Created by 이정동 on 5/5/25. +// + +import Foundation + +@Observable +final class RootViewModel: Reducer { + struct State { + var isSplashVisible: Bool = true + } + + enum Action { + case onAppear + } + + private(set) var state: State = .init() + private(set) var sharedState: AppState + + private let fetchCurrentUserIDUseCase: FetchCurrentUserIDUseCase + + init() { + self.sharedState = DIContainer.shared.resolve() + self.fetchCurrentUserIDUseCase = DIContainer.shared.resolve() + } + + func send(_ action: Action) { + let effect = reduce(state: &state, action: action) + handleEffect(effect) + } + + func reduce(state: inout State, action: Action) -> Effect { + switch action { + case .onAppear: + let uid = fetchCurrentUserIDUseCase.execute() + state.isSplashVisible = false + sharedState.isLoginned = uid != nil + return .none + } + } + + private func handleEffect(_ effect: Effect) { + switch effect { + case .none: + break + case .run(let action): + Task { + let newAction = await action() + send(newAction) + } + } + } +} From 5f5c5ed3d9f2bb6e5728d933b6b96995e22990e4 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Mon, 5 May 2025 16:11:53 +0900 Subject: [PATCH 05/22] =?UTF-8?q?[#28]=20RootView=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/RootView.swift | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Mark-In/Sources/App/RootView.swift diff --git a/Mark-In/Sources/App/RootView.swift b/Mark-In/Sources/App/RootView.swift new file mode 100644 index 0000000..d471fb5 --- /dev/null +++ b/Mark-In/Sources/App/RootView.swift @@ -0,0 +1,53 @@ +// +// RootView.swift +// Mark-In +// +// Created by 이정동 on 5/5/25. +// + +import SwiftUI + +import DesignSystem + +struct RootView: View { + + @State private var rootViewModel = RootViewModel() + + var body: some View { + ZStack { + if rootViewModel.state.isSplashVisible { + SplashView() + } else { + if rootViewModel.sharedState.isLoginned { + MainView() + } else { + LoginView() + } + } + } + .onAppear { + rootViewModel.send(.onAppear) + } + } +} + + +private struct SplashView: View { + + var body: some View { + ZStack { + LinearGradient( + colors: [.markPoint, .markWhite], + startPoint: .top, + endPoint: .bottom + ) + .ignoresSafeArea() + + Text("Splash View") + } + } +} + +#Preview { + RootView() +} From 905120406514f435f183c87369878a43d2fddeb3 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Mon, 5 May 2025 16:13:33 +0900 Subject: [PATCH 06/22] =?UTF-8?q?[#28]=20Root=20View=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20=EB=B0=8F=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/Mark_InApp.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Mark-In/Sources/App/Mark_InApp.swift b/Mark-In/Sources/App/Mark_InApp.swift index a945642..6bbcf17 100644 --- a/Mark-In/Sources/App/Mark_InApp.swift +++ b/Mark-In/Sources/App/Mark_InApp.swift @@ -20,11 +20,13 @@ struct Mark_InApp: App { configureFirebase() configureGoogleSignIn() + + DIContainer.shared.registerDependencies() } var body: some Scene { WindowGroup { - MainView() + RootView() .frame(minWidth: 500, minHeight: 500) .onOpenURL { url in GIDSignIn.sharedInstance.handle(url) From f30b7a3c631471587d81cc49f89d55ef1aafd849 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Mon, 5 May 2025 16:15:43 +0900 Subject: [PATCH 07/22] =?UTF-8?q?[#28]=20LoginViewModel=EC=97=90=20?= =?UTF-8?q?=EC=A0=84=EC=97=AD=20=EC=83=81=ED=83=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/Feature/Login/LoginViewModel.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Mark-In/Sources/Feature/Login/LoginViewModel.swift b/Mark-In/Sources/Feature/Login/LoginViewModel.swift index cdd764c..3df7e28 100644 --- a/Mark-In/Sources/Feature/Login/LoginViewModel.swift +++ b/Mark-In/Sources/Feature/Login/LoginViewModel.swift @@ -17,7 +17,7 @@ import Util @Observable final class LoginViewModel: Reducer { struct State { - var isSignInSuccess: Bool = false + // TODO: 로그인 실패 시 알림 화면을 보여줄 상태 구현 생각 중 } enum Action { @@ -33,6 +33,11 @@ final class LoginViewModel: Reducer { } private(set) var state: State = .init() + private(set) var sharedState: AppState + + init() { + self.sharedState = DIContainer.shared.resolve() + } func send(_ action: Action) { let effect = reduce(state: &state, action: action) @@ -119,7 +124,7 @@ final class LoginViewModel: Reducer { case .firebaseAuthResponse(let result): switch result { case .success(_): - state.isSignInSuccess = true + sharedState.isLoginned = true case .failure(let error): // TODO: 에러 처리 필요 let _ = error as? AuthErrorCode From f8bad8130dfbf15e9bf5b89c3c9f0e28838910c0 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Wed, 7 May 2025 02:25:11 +0900 Subject: [PATCH 08/22] =?UTF-8?q?[#28]=20Reducer=20=EB=B0=8F=20ViewModel?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/RootViewModel.swift | 4 ++-- Mark-In/Sources/Feature/Common/Reducer.swift | 3 +-- Mark-In/Sources/Feature/Login/LoginViewModel.swift | 4 ++-- Mark-In/Sources/Feature/Main/MainViewModel.swift | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Mark-In/Sources/App/RootViewModel.swift b/Mark-In/Sources/App/RootViewModel.swift index d2b3c63..0b7b82d 100644 --- a/Mark-In/Sources/App/RootViewModel.swift +++ b/Mark-In/Sources/App/RootViewModel.swift @@ -47,9 +47,9 @@ final class RootViewModel: Reducer { case .none: break case .run(let action): - Task { + Task.detached { [weak self] in let newAction = await action() - send(newAction) + await self?.send(newAction) } } } diff --git a/Mark-In/Sources/Feature/Common/Reducer.swift b/Mark-In/Sources/Feature/Common/Reducer.swift index 0df23a5..0f30140 100644 --- a/Mark-In/Sources/Feature/Common/Reducer.swift +++ b/Mark-In/Sources/Feature/Common/Reducer.swift @@ -7,14 +7,13 @@ import Foundation +@MainActor protocol Reducer { associatedtype State associatedtype Action - @MainActor func send(_ action: Action) - @MainActor func reduce(state: inout State, action: Action) -> Effect } diff --git a/Mark-In/Sources/Feature/Login/LoginViewModel.swift b/Mark-In/Sources/Feature/Login/LoginViewModel.swift index 3df7e28..a441740 100644 --- a/Mark-In/Sources/Feature/Login/LoginViewModel.swift +++ b/Mark-In/Sources/Feature/Login/LoginViewModel.swift @@ -142,9 +142,9 @@ final class LoginViewModel: Reducer { case .none: break case .run(let action): - Task { + Task.detached { [weak self] in let newAction = await action() - await send(newAction) + await self?.send(newAction) } } } diff --git a/Mark-In/Sources/Feature/Main/MainViewModel.swift b/Mark-In/Sources/Feature/Main/MainViewModel.swift index 6aaed15..136f4c3 100644 --- a/Mark-In/Sources/Feature/Main/MainViewModel.swift +++ b/Mark-In/Sources/Feature/Main/MainViewModel.swift @@ -7,7 +7,7 @@ import Foundation -@MainActor @Observable +@Observable final class MainViewModel: Reducer { struct State { var isLoading: Bool = true From e33cd23b7e410fa88477ac9024f63058b77e71d3 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Wed, 7 May 2025 02:26:49 +0900 Subject: [PATCH 09/22] =?UTF-8?q?[#28]=20DIContainer=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=20=EB=B0=8F=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/DIContainer.swift | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Mark-In/Sources/App/DIContainer.swift b/Mark-In/Sources/App/DIContainer.swift index 20ceaa7..8977066 100644 --- a/Mark-In/Sources/App/DIContainer.swift +++ b/Mark-In/Sources/App/DIContainer.swift @@ -7,6 +7,9 @@ import Foundation +import LinkMetadataKit +import LinkMetadataKitInterface + // TODO: 코어 모듈로 이전 final class DIContainer { static let shared = DIContainer() @@ -44,18 +47,27 @@ extension DIContainer { register(appState) + /// Core + let linkMetadataProvider: LinkMetadataProvider = LinkMetadataProviderImpl() + + register(linkMetadataProvider) + /// Repository - let authRepository = AuthRepositoryImpl() - let folderRepository = FolderRepositoryImpl() - let linkRepository = LinkRepositoryImpl() + let authRepository: AuthRepository = AuthRepositoryImpl() + let folderRepository: FolderRepository = FolderRepositoryImpl() + let linkRepository: LinkRepository = LinkRepositoryImpl( + linkMetadataProvider: linkMetadataProvider + ) - register(authRepository as AuthRepository) - register(folderRepository as FolderRepository) - register(linkRepository as LinkRepository) + register(authRepository) + register(folderRepository) + register(linkRepository) /// UseCase - let fetchCurrentUserIDUseCase = FetchCurrentUserIDUseCaseImpl(authRepository: authRepository) + let fetchCurrentUserIDUseCase: FetchCurrentUserIDUseCase = FetchCurrentUserIDUseCaseImpl( + authRepository: authRepository + ) - register(fetchCurrentUserIDUseCase as FetchCurrentUserIDUseCase) + register(fetchCurrentUserIDUseCase) } } From 096b91cde6b9e216e5f018be63833745a4758d8f Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Wed, 7 May 2025 02:27:06 +0900 Subject: [PATCH 10/22] =?UTF-8?q?[#28]=20OAuthProvider=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/Feature/Login/LoginView.swift | 2 +- Shared/Util/Sources/OAuthProvider.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mark-In/Sources/Feature/Login/LoginView.swift b/Mark-In/Sources/Feature/Login/LoginView.swift index e413a96..5d39f4e 100644 --- a/Mark-In/Sources/Feature/Login/LoginView.swift +++ b/Mark-In/Sources/Feature/Login/LoginView.swift @@ -117,7 +117,7 @@ private struct SignInButtonList: View { } private struct SignInButton: View { - let provider: OAuthProvider + let provider: SocialSignInProvider let action: () -> Void diff --git a/Shared/Util/Sources/OAuthProvider.swift b/Shared/Util/Sources/OAuthProvider.swift index be1629f..c5cb681 100644 --- a/Shared/Util/Sources/OAuthProvider.swift +++ b/Shared/Util/Sources/OAuthProvider.swift @@ -7,7 +7,7 @@ import Foundation -public enum OAuthProvider { +public enum SocialSignInProvider { case apple case google } From 3bbd0dd050b6f429e04706682b0bef8c81de15fd Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Thu, 8 May 2025 13:15:36 +0900 Subject: [PATCH 11/22] =?UTF-8?q?[#28]=20AuthManager=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/AuthManager.swift | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Mark-In/Sources/App/AuthManager.swift diff --git a/Mark-In/Sources/App/AuthManager.swift b/Mark-In/Sources/App/AuthManager.swift new file mode 100644 index 0000000..69b5366 --- /dev/null +++ b/Mark-In/Sources/App/AuthManager.swift @@ -0,0 +1,50 @@ +// +// AuthManager.swift +// Mark-In +// +// Created by 이정동 on 5/8/25. +// + +// TODO: Core 모듈로 이전 예정 + +import Combine +import Foundation + +import FirebaseAuth + +struct UserModel { + let id: String +} + +protocol AuthManager { + var userEvent: PassthroughSubject { get } + + func checkLoginStatus() + func setCurrentUser(id: String) + func clearCurrentUser() +} + +final class AuthManagerImpl: AuthManager { + var userEvent: PassthroughSubject = .init() + + private var currentUser: UserModel? + + func checkLoginStatus() { + if let user = Auth.auth().currentUser { + setCurrentUser(id: user.uid) + } else { + clearCurrentUser() + } + } + + func setCurrentUser(id: String) { + let user = UserModel(id: id) + userEvent.send(user) + currentUser = user + } + + func clearCurrentUser() { + userEvent.send(nil) + currentUser = nil + } +} From bf7ca645eb2934a2ed377c0b4129733dbae42b26 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Thu, 8 May 2025 13:16:23 +0900 Subject: [PATCH 12/22] =?UTF-8?q?[#28]=20AuthManager=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/DIContainer.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Mark-In/Sources/App/DIContainer.swift b/Mark-In/Sources/App/DIContainer.swift index 8977066..449aacf 100644 --- a/Mark-In/Sources/App/DIContainer.swift +++ b/Mark-In/Sources/App/DIContainer.swift @@ -49,8 +49,10 @@ extension DIContainer { /// Core let linkMetadataProvider: LinkMetadataProvider = LinkMetadataProviderImpl() + let authSessionManager: AuthManager = AuthManagerImpl() register(linkMetadataProvider) + register(authSessionManager) /// Repository let authRepository: AuthRepository = AuthRepositoryImpl() From d26df3445ff7da097a1a3c0c36740c974615bd5d Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Thu, 8 May 2025 13:17:08 +0900 Subject: [PATCH 13/22] =?UTF-8?q?[#28]=20=EA=B8=B0=EC=A1=B4=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EC=97=90=20AuthManager=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/RootView.swift | 2 +- Mark-In/Sources/App/RootViewModel.swift | 25 +++++++++++++------ .../Feature/Login/LoginViewModel.swift | 14 +++++------ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Mark-In/Sources/App/RootView.swift b/Mark-In/Sources/App/RootView.swift index d471fb5..1c6f9c7 100644 --- a/Mark-In/Sources/App/RootView.swift +++ b/Mark-In/Sources/App/RootView.swift @@ -18,7 +18,7 @@ struct RootView: View { if rootViewModel.state.isSplashVisible { SplashView() } else { - if rootViewModel.sharedState.isLoginned { + if rootViewModel.state.currentUser != nil { MainView() } else { LoginView() diff --git a/Mark-In/Sources/App/RootViewModel.swift b/Mark-In/Sources/App/RootViewModel.swift index 0b7b82d..d30191a 100644 --- a/Mark-In/Sources/App/RootViewModel.swift +++ b/Mark-In/Sources/App/RootViewModel.swift @@ -5,26 +5,35 @@ // Created by 이정동 on 5/5/25. // +import Combine import Foundation @Observable final class RootViewModel: Reducer { struct State { var isSplashVisible: Bool = true + var currentUser: UserModel? = nil } enum Action { case onAppear + case receiveCurrentUserEvent(UserModel?) } - private(set) var state: State = .init() - private(set) var sharedState: AppState + private let authManager: AuthManager - private let fetchCurrentUserIDUseCase: FetchCurrentUserIDUseCase + private(set) var state: State = .init() + private var cancellables = Set() init() { - self.sharedState = DIContainer.shared.resolve() - self.fetchCurrentUserIDUseCase = DIContainer.shared.resolve() + self.authManager = DIContainer.shared.resolve() + + self.authManager.userEvent + .receive(on: RunLoop.main) + .sink { [weak self] value in + self?.send(.receiveCurrentUserEvent(value)) + } + .store(in: &cancellables) } func send(_ action: Action) { @@ -35,9 +44,11 @@ final class RootViewModel: Reducer { func reduce(state: inout State, action: Action) -> Effect { switch action { case .onAppear: - let uid = fetchCurrentUserIDUseCase.execute() + authManager.checkLoginStatus() + return .none + case .receiveCurrentUserEvent(let currentUser): + state.currentUser = currentUser state.isSplashVisible = false - sharedState.isLoginned = uid != nil return .none } } diff --git a/Mark-In/Sources/Feature/Login/LoginViewModel.swift b/Mark-In/Sources/Feature/Login/LoginViewModel.swift index a441740..6e8c179 100644 --- a/Mark-In/Sources/Feature/Login/LoginViewModel.swift +++ b/Mark-In/Sources/Feature/Login/LoginViewModel.swift @@ -27,16 +27,16 @@ final class LoginViewModel: Reducer { case signInError(SignInError) case firebaseAuthRequest(AuthCredential) - case firebaseAuthResponse(Result) + case firebaseAuthResponse(Result) case empty } private(set) var state: State = .init() - private(set) var sharedState: AppState + private let authSessionManager: AuthManager init() { - self.sharedState = DIContainer.shared.resolve() + self.authSessionManager = DIContainer.shared.resolve() } func send(_ action: Action) { @@ -113,9 +113,9 @@ final class LoginViewModel: Reducer { return .run { do { /// Firebase 인증 요청 - let _ = try await Auth.auth().signIn(with: credential) + let response = try await Auth.auth().signIn(with: credential) - return .firebaseAuthResponse(.success(())) + return .firebaseAuthResponse(.success(response.user.uid)) } catch { return .firebaseAuthResponse(.failure(error)) } @@ -123,8 +123,8 @@ final class LoginViewModel: Reducer { case .firebaseAuthResponse(let result): switch result { - case .success(_): - sharedState.isLoginned = true + case .success(let id): + authSessionManager.setCurrentUser(id: id) case .failure(let error): // TODO: 에러 처리 필요 let _ = error as? AuthErrorCode From 73238550e657406e7e3158a64e609a2781f379e7 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Thu, 8 May 2025 13:19:47 +0900 Subject: [PATCH 14/22] =?UTF-8?q?[#28]=20UseCase,=20Repository,=20AppState?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/DIContainer.swift | 19 ----------------- .../Repositories/AuthRepositoryImpl.swift | 17 --------------- .../Domain/Interfaces/AuthRepository.swift | 12 ----------- .../FetchCurrentUserIDUseCaseImpl.swift | 21 ------------------- .../FetchCurrentUserIDUseCase.swift | 12 ----------- 5 files changed, 81 deletions(-) delete mode 100644 Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift delete mode 100644 Mark-In/Sources/Domain/Interfaces/AuthRepository.swift delete mode 100644 Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift delete mode 100644 Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift diff --git a/Mark-In/Sources/App/DIContainer.swift b/Mark-In/Sources/App/DIContainer.swift index 449aacf..46875f4 100644 --- a/Mark-In/Sources/App/DIContainer.swift +++ b/Mark-In/Sources/App/DIContainer.swift @@ -34,18 +34,8 @@ final class DIContainer { } } -// TODO: Core 모듈 or Feature(공통) 모듈 중 어느 곳이 적합한지 고민 -@Observable -final class AppState { - var isLoginned: Bool = false -} - extension DIContainer { func registerDependencies() { - /// AppState - let appState = AppState() - - register(appState) /// Core let linkMetadataProvider: LinkMetadataProvider = LinkMetadataProviderImpl() @@ -55,21 +45,12 @@ extension DIContainer { register(authSessionManager) /// Repository - let authRepository: AuthRepository = AuthRepositoryImpl() let folderRepository: FolderRepository = FolderRepositoryImpl() let linkRepository: LinkRepository = LinkRepositoryImpl( linkMetadataProvider: linkMetadataProvider ) - register(authRepository) register(folderRepository) register(linkRepository) - - /// UseCase - let fetchCurrentUserIDUseCase: FetchCurrentUserIDUseCase = FetchCurrentUserIDUseCaseImpl( - authRepository: authRepository - ) - - register(fetchCurrentUserIDUseCase) } } diff --git a/Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift b/Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift deleted file mode 100644 index 42d7080..0000000 --- a/Mark-In/Sources/Data/Repositories/AuthRepositoryImpl.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// AuthRepositoryImpl.swift -// Mark-In -// -// Created by 이정동 on 5/5/25. -// - -import Foundation - -import FirebaseAuth - -struct AuthRepositoryImpl: AuthRepository { - func fetchCurrentUserID() -> String? { - let user = Auth.auth().currentUser - return user?.uid - } -} diff --git a/Mark-In/Sources/Domain/Interfaces/AuthRepository.swift b/Mark-In/Sources/Domain/Interfaces/AuthRepository.swift deleted file mode 100644 index 9a4acda..0000000 --- a/Mark-In/Sources/Domain/Interfaces/AuthRepository.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// AuthRepository.swift -// Mark-In -// -// Created by 이정동 on 5/5/25. -// - -import Foundation - -protocol AuthRepository { - func fetchCurrentUserID() -> String? -} diff --git a/Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift b/Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift deleted file mode 100644 index 9266447..0000000 --- a/Mark-In/Sources/Domain/UseCases/Implements/FetchCurrentUserIDUseCaseImpl.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// FetchCurrentUserIDUseCaseImpl.swift -// Mark-In -// -// Created by 이정동 on 5/5/25. -// - -import Foundation - -struct FetchCurrentUserIDUseCaseImpl: FetchCurrentUserIDUseCase { - - private let authRepository: AuthRepository - - init(authRepository: AuthRepository) { - self.authRepository = authRepository - } - - func execute() -> String? { - authRepository.fetchCurrentUserID() - } -} diff --git a/Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift b/Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift deleted file mode 100644 index 59c6e33..0000000 --- a/Mark-In/Sources/Domain/UseCases/Interfaces/FetchCurrentUserIDUseCase.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// FetchCurrentUserIDUseCase.swift -// Mark-In -// -// Created by 이정동 on 5/5/25. -// - -import Foundation - -protocol FetchCurrentUserIDUseCase { - func execute() -> String? -} From ee0ca90a40f68e8632b38b013cb159839ad167f7 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Thu, 8 May 2025 13:26:35 +0900 Subject: [PATCH 15/22] =?UTF-8?q?[#28]=20AuthManager=20=EB=82=B4=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/AuthManager.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Mark-In/Sources/App/AuthManager.swift b/Mark-In/Sources/App/AuthManager.swift index 69b5366..a7ee42f 100644 --- a/Mark-In/Sources/App/AuthManager.swift +++ b/Mark-In/Sources/App/AuthManager.swift @@ -21,6 +21,7 @@ protocol AuthManager { func checkLoginStatus() func setCurrentUser(id: String) + func getCurrentUser() -> UserModel? func clearCurrentUser() } @@ -43,6 +44,10 @@ final class AuthManagerImpl: AuthManager { currentUser = user } + func getCurrentUser() -> UserModel? { + return currentUser + } + func clearCurrentUser() { userEvent.send(nil) currentUser = nil From cbae69b09b9f80d404f055e29384b6e1a7319dd2 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Sun, 11 May 2025 12:21:17 +0900 Subject: [PATCH 16/22] =?UTF-8?q?[#28]=20AuthManager=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/AuthManager.swift | 37 +++++++++------------------ 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/Mark-In/Sources/App/AuthManager.swift b/Mark-In/Sources/App/AuthManager.swift index a7ee42f..b7c3494 100644 --- a/Mark-In/Sources/App/AuthManager.swift +++ b/Mark-In/Sources/App/AuthManager.swift @@ -7,7 +7,6 @@ // TODO: Core 모듈로 이전 예정 -import Combine import Foundation import FirebaseAuth @@ -17,39 +16,27 @@ struct UserModel { } protocol AuthManager { - var userEvent: PassthroughSubject { get } + var user: UserModel? { get } - func checkLoginStatus() - func setCurrentUser(id: String) - func getCurrentUser() -> UserModel? - func clearCurrentUser() + func saveUser(id: String) + func clear() } +@Observable final class AuthManagerImpl: AuthManager { - var userEvent: PassthroughSubject = .init() + var user: UserModel? - private var currentUser: UserModel? - - func checkLoginStatus() { - if let user = Auth.auth().currentUser { - setCurrentUser(id: user.uid) - } else { - clearCurrentUser() - } + init() { + guard let currentUser = Auth.auth().currentUser else { return } + self.user = UserModel(id: currentUser.uid) } - func setCurrentUser(id: String) { + func saveUser(id: String) { let user = UserModel(id: id) - userEvent.send(user) - currentUser = user - } - - func getCurrentUser() -> UserModel? { - return currentUser + self.user = user } - func clearCurrentUser() { - userEvent.send(nil) - currentUser = nil + func clear() { + user = nil } } From 023348f784dce99011dac52fb705d4046669d4fc Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Sun, 11 May 2025 12:21:57 +0900 Subject: [PATCH 17/22] =?UTF-8?q?[#28]=20=EC=88=98=EC=A0=95=EB=90=9C=20Aut?= =?UTF-8?q?hManager=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/DIContainer.swift | 4 +-- Mark-In/Sources/App/RootView.swift | 32 +++---------------- .../Feature/Login/LoginViewModel.swift | 6 ++-- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/Mark-In/Sources/App/DIContainer.swift b/Mark-In/Sources/App/DIContainer.swift index 46875f4..1b329d2 100644 --- a/Mark-In/Sources/App/DIContainer.swift +++ b/Mark-In/Sources/App/DIContainer.swift @@ -39,10 +39,10 @@ extension DIContainer { /// Core let linkMetadataProvider: LinkMetadataProvider = LinkMetadataProviderImpl() - let authSessionManager: AuthManager = AuthManagerImpl() + let authManager: AuthManager = AuthManagerImpl() register(linkMetadataProvider) - register(authSessionManager) + register(authManager) /// Repository let folderRepository: FolderRepository = FolderRepositoryImpl() diff --git a/Mark-In/Sources/App/RootView.swift b/Mark-In/Sources/App/RootView.swift index 1c6f9c7..2221931 100644 --- a/Mark-In/Sources/App/RootView.swift +++ b/Mark-In/Sources/App/RootView.swift @@ -11,40 +11,16 @@ import DesignSystem struct RootView: View { - @State private var rootViewModel = RootViewModel() + @State private var authManager: AuthManager = DIContainer.shared.resolve() var body: some View { ZStack { - if rootViewModel.state.isSplashVisible { - SplashView() + if authManager.user != nil { + MainView() } else { - if rootViewModel.state.currentUser != nil { - MainView() - } else { - LoginView() - } + LoginView() } } - .onAppear { - rootViewModel.send(.onAppear) - } - } -} - - -private struct SplashView: View { - - var body: some View { - ZStack { - LinearGradient( - colors: [.markPoint, .markWhite], - startPoint: .top, - endPoint: .bottom - ) - .ignoresSafeArea() - - Text("Splash View") - } } } diff --git a/Mark-In/Sources/Feature/Login/LoginViewModel.swift b/Mark-In/Sources/Feature/Login/LoginViewModel.swift index 6e8c179..cc25063 100644 --- a/Mark-In/Sources/Feature/Login/LoginViewModel.swift +++ b/Mark-In/Sources/Feature/Login/LoginViewModel.swift @@ -33,10 +33,10 @@ final class LoginViewModel: Reducer { } private(set) var state: State = .init() - private let authSessionManager: AuthManager + private let authManager: AuthManager init() { - self.authSessionManager = DIContainer.shared.resolve() + self.authManager = DIContainer.shared.resolve() } func send(_ action: Action) { @@ -124,7 +124,7 @@ final class LoginViewModel: Reducer { case .firebaseAuthResponse(let result): switch result { case .success(let id): - authSessionManager.setCurrentUser(id: id) + authManager.saveUser(id: id) case .failure(let error): // TODO: 에러 처리 필요 let _ = error as? AuthErrorCode From ac2ba788532f27796991d67d6c90e321dedfd7ff Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Sun, 11 May 2025 12:22:08 +0900 Subject: [PATCH 18/22] =?UTF-8?q?[#28]=20RootViewModel=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/RootViewModel.swift | 67 ------------------------- 1 file changed, 67 deletions(-) delete mode 100644 Mark-In/Sources/App/RootViewModel.swift diff --git a/Mark-In/Sources/App/RootViewModel.swift b/Mark-In/Sources/App/RootViewModel.swift deleted file mode 100644 index d30191a..0000000 --- a/Mark-In/Sources/App/RootViewModel.swift +++ /dev/null @@ -1,67 +0,0 @@ -// -// RootViewModel.swift -// Mark-In -// -// Created by 이정동 on 5/5/25. -// - -import Combine -import Foundation - -@Observable -final class RootViewModel: Reducer { - struct State { - var isSplashVisible: Bool = true - var currentUser: UserModel? = nil - } - - enum Action { - case onAppear - case receiveCurrentUserEvent(UserModel?) - } - - private let authManager: AuthManager - - private(set) var state: State = .init() - private var cancellables = Set() - - init() { - self.authManager = DIContainer.shared.resolve() - - self.authManager.userEvent - .receive(on: RunLoop.main) - .sink { [weak self] value in - self?.send(.receiveCurrentUserEvent(value)) - } - .store(in: &cancellables) - } - - func send(_ action: Action) { - let effect = reduce(state: &state, action: action) - handleEffect(effect) - } - - func reduce(state: inout State, action: Action) -> Effect { - switch action { - case .onAppear: - authManager.checkLoginStatus() - return .none - case .receiveCurrentUserEvent(let currentUser): - state.currentUser = currentUser - state.isSplashVisible = false - return .none - } - } - - private func handleEffect(_ effect: Effect) { - switch effect { - case .none: - break - case .run(let action): - Task.detached { [weak self] in - let newAction = await action() - await self?.send(newAction) - } - } - } -} From 3ce1a2def50087116bc08a0515e83a5a9af5baaa Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Tue, 13 May 2025 01:07:37 +0900 Subject: [PATCH 19/22] =?UTF-8?q?[#28]=20AuthManager=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{AuthManager.swift => AuthUserManager.swift} | 14 +++++++------- Mark-In/Sources/App/DIContainer.swift | 4 ++-- Mark-In/Sources/App/RootView.swift | 4 ++-- Mark-In/Sources/Feature/Login/LoginViewModel.swift | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) rename Mark-In/Sources/App/{AuthManager.swift => AuthUserManager.swift} (65%) diff --git a/Mark-In/Sources/App/AuthManager.swift b/Mark-In/Sources/App/AuthUserManager.swift similarity index 65% rename from Mark-In/Sources/App/AuthManager.swift rename to Mark-In/Sources/App/AuthUserManager.swift index b7c3494..ea42d0a 100644 --- a/Mark-In/Sources/App/AuthManager.swift +++ b/Mark-In/Sources/App/AuthUserManager.swift @@ -11,28 +11,28 @@ import Foundation import FirebaseAuth -struct UserModel { +struct AuthUser { let id: String } -protocol AuthManager { - var user: UserModel? { get } +protocol AuthUserManager { + var user: AuthUser? { get } func saveUser(id: String) func clear() } @Observable -final class AuthManagerImpl: AuthManager { - var user: UserModel? +final class AuthUserManagerImpl: AuthUserManager { + var user: AuthUser? init() { guard let currentUser = Auth.auth().currentUser else { return } - self.user = UserModel(id: currentUser.uid) + self.user = AuthUser(id: currentUser.uid) } func saveUser(id: String) { - let user = UserModel(id: id) + let user = AuthUser(id: id) self.user = user } diff --git a/Mark-In/Sources/App/DIContainer.swift b/Mark-In/Sources/App/DIContainer.swift index 1b329d2..c6de151 100644 --- a/Mark-In/Sources/App/DIContainer.swift +++ b/Mark-In/Sources/App/DIContainer.swift @@ -39,10 +39,10 @@ extension DIContainer { /// Core let linkMetadataProvider: LinkMetadataProvider = LinkMetadataProviderImpl() - let authManager: AuthManager = AuthManagerImpl() + let authUserManager: AuthUserManager = AuthUserManagerImpl() register(linkMetadataProvider) - register(authManager) + register(authUserManager) /// Repository let folderRepository: FolderRepository = FolderRepositoryImpl() diff --git a/Mark-In/Sources/App/RootView.swift b/Mark-In/Sources/App/RootView.swift index 2221931..9c758de 100644 --- a/Mark-In/Sources/App/RootView.swift +++ b/Mark-In/Sources/App/RootView.swift @@ -11,11 +11,11 @@ import DesignSystem struct RootView: View { - @State private var authManager: AuthManager = DIContainer.shared.resolve() + @State private var authUserManager: AuthUserManager = DIContainer.shared.resolve() var body: some View { ZStack { - if authManager.user != nil { + if authUserManager.user != nil { MainView() } else { LoginView() diff --git a/Mark-In/Sources/Feature/Login/LoginViewModel.swift b/Mark-In/Sources/Feature/Login/LoginViewModel.swift index cc25063..0a31249 100644 --- a/Mark-In/Sources/Feature/Login/LoginViewModel.swift +++ b/Mark-In/Sources/Feature/Login/LoginViewModel.swift @@ -33,10 +33,10 @@ final class LoginViewModel: Reducer { } private(set) var state: State = .init() - private let authManager: AuthManager + private let authUserManager: AuthUserManager init() { - self.authManager = DIContainer.shared.resolve() + self.authUserManager = DIContainer.shared.resolve() } func send(_ action: Action) { @@ -124,7 +124,7 @@ final class LoginViewModel: Reducer { case .firebaseAuthResponse(let result): switch result { case .success(let id): - authManager.saveUser(id: id) + authUserManager.saveUser(id: id) case .failure(let error): // TODO: 에러 처리 필요 let _ = error as? AuthErrorCode From c52ea13e49bfcd5fe502fa51acd6e881211391c5 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Tue, 13 May 2025 01:09:21 +0900 Subject: [PATCH 20/22] =?UTF-8?q?[#28]=20saveUser=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/AuthUserManager.swift | 5 ++--- Mark-In/Sources/Feature/Login/LoginViewModel.swift | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Mark-In/Sources/App/AuthUserManager.swift b/Mark-In/Sources/App/AuthUserManager.swift index ea42d0a..fcb694f 100644 --- a/Mark-In/Sources/App/AuthUserManager.swift +++ b/Mark-In/Sources/App/AuthUserManager.swift @@ -18,7 +18,7 @@ struct AuthUser { protocol AuthUserManager { var user: AuthUser? { get } - func saveUser(id: String) + func saveUser(_ user: AuthUser) func clear() } @@ -31,8 +31,7 @@ final class AuthUserManagerImpl: AuthUserManager { self.user = AuthUser(id: currentUser.uid) } - func saveUser(id: String) { - let user = AuthUser(id: id) + func saveUser(_ user: AuthUser) { self.user = user } diff --git a/Mark-In/Sources/Feature/Login/LoginViewModel.swift b/Mark-In/Sources/Feature/Login/LoginViewModel.swift index 0a31249..ceda2d6 100644 --- a/Mark-In/Sources/Feature/Login/LoginViewModel.swift +++ b/Mark-In/Sources/Feature/Login/LoginViewModel.swift @@ -124,7 +124,8 @@ final class LoginViewModel: Reducer { case .firebaseAuthResponse(let result): switch result { case .success(let id): - authUserManager.saveUser(id: id) + let user = AuthUser(id: id) + authUserManager.saveUser(user) case .failure(let error): // TODO: 에러 처리 필요 let _ = error as? AuthErrorCode From 344de2cd00b3172784f17f555d912a77a2ab11bf Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Tue, 13 May 2025 01:13:37 +0900 Subject: [PATCH 21/22] =?UTF-8?q?[#28]=20AuthUserManager=EC=97=90=20load()?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/AuthUserManager.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Mark-In/Sources/App/AuthUserManager.swift b/Mark-In/Sources/App/AuthUserManager.swift index fcb694f..c27d58c 100644 --- a/Mark-In/Sources/App/AuthUserManager.swift +++ b/Mark-In/Sources/App/AuthUserManager.swift @@ -19,6 +19,7 @@ protocol AuthUserManager { var user: AuthUser? { get } func saveUser(_ user: AuthUser) + func load() func clear() } @@ -27,6 +28,10 @@ final class AuthUserManagerImpl: AuthUserManager { var user: AuthUser? init() { + self.load() + } + + func load() { guard let currentUser = Auth.auth().currentUser else { return } self.user = AuthUser(id: currentUser.uid) } From 7783d2d4c057059d3149db7811a419d2726ef513 Mon Sep 17 00:00:00 2001 From: Jeong Dong Date: Tue, 13 May 2025 01:19:13 +0900 Subject: [PATCH 22/22] =?UTF-8?q?[#28]=20save()=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mark-In/Sources/App/AuthUserManager.swift | 4 ++-- Mark-In/Sources/Feature/Login/LoginViewModel.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Mark-In/Sources/App/AuthUserManager.swift b/Mark-In/Sources/App/AuthUserManager.swift index c27d58c..871285c 100644 --- a/Mark-In/Sources/App/AuthUserManager.swift +++ b/Mark-In/Sources/App/AuthUserManager.swift @@ -18,7 +18,7 @@ struct AuthUser { protocol AuthUserManager { var user: AuthUser? { get } - func saveUser(_ user: AuthUser) + func save(_ user: AuthUser) func load() func clear() } @@ -36,7 +36,7 @@ final class AuthUserManagerImpl: AuthUserManager { self.user = AuthUser(id: currentUser.uid) } - func saveUser(_ user: AuthUser) { + func save(_ user: AuthUser) { self.user = user } diff --git a/Mark-In/Sources/Feature/Login/LoginViewModel.swift b/Mark-In/Sources/Feature/Login/LoginViewModel.swift index ceda2d6..9a2c7d4 100644 --- a/Mark-In/Sources/Feature/Login/LoginViewModel.swift +++ b/Mark-In/Sources/Feature/Login/LoginViewModel.swift @@ -125,7 +125,7 @@ final class LoginViewModel: Reducer { switch result { case .success(let id): let user = AuthUser(id: id) - authUserManager.saveUser(user) + authUserManager.save(user) case .failure(let error): // TODO: 에러 처리 필요 let _ = error as? AuthErrorCode