diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/CoreAuthRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/CoreAuthRepository.swift index 2a13ee98..d50a49db 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/CoreAuthRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/CoreAuthRepository.swift @@ -1,9 +1,33 @@ // -// CoreAuthRepository.swift +// CoreOAuthRepository.swift // Data // // Created by 장석우 on 1/18/25. // Copyright © 2025 SOPT-iOS. All rights reserved. // +import Combine import Foundation + +import Domain +import Networks + +public class CoreOAuthRepository { + + private let appleService: AuthenticationService +// private let googleService: + + public init(appleService: AuthenticationService) { + self.appleService = appleService + } +} + +extension CoreOAuthRepository: CoreOAuthRepositoryInterface { + public func getIdentityToken(from provider: OAuthType) -> AnyPublisher { + switch provider { + case .apple: return appleService.getIdentityToken() + case .google: fatalError() //TODO: + } + + } +} diff --git a/SOPT-iOS/Projects/Data/Sources/Repository/SignInRepository.swift b/SOPT-iOS/Projects/Data/Sources/Repository/SignInRepository.swift index 85538000..7a27d058 100644 --- a/SOPT-iOS/Projects/Data/Sources/Repository/SignInRepository.swift +++ b/SOPT-iOS/Projects/Data/Sources/Repository/SignInRepository.swift @@ -19,6 +19,7 @@ public class SignInRepository { private let authService: AuthService private let userService: UserService + private let cancelBag = CancelBag() public init(authService: AuthService, userService: UserService) { @@ -28,6 +29,7 @@ public class SignInRepository { } extension SignInRepository: SignInRepositoryInterface { + public func requestSignIn(token: String) -> AnyPublisher { return authService.signIn(token: token) .catch ({ error in diff --git a/SOPT-iOS/Projects/Demo/Sources/Dependency/RegisterDependencies.swift b/SOPT-iOS/Projects/Demo/Sources/Dependency/RegisterDependencies.swift index df3fb848..177df345 100644 --- a/SOPT-iOS/Projects/Demo/Sources/Dependency/RegisterDependencies.swift +++ b/SOPT-iOS/Projects/Demo/Sources/Dependency/RegisterDependencies.swift @@ -27,12 +27,21 @@ extension AppDelegate { ) } ) + + container.register( + interface: CoreOAuthRepositoryInterface.self, + implement: { + CoreOAuthRepository(appleService: DefaultAppleAuthenticationService()) + } + ) + container.register( interface: SplashRepositoryInterface.self, implement: { SplashRepository(service: DefaultFirebaseService()) } ) + container.register( interface: MainRepositoryInterface.self, implement: { diff --git a/SOPT-iOS/Projects/Domain/Sources/Error/CoreAuthError.swift b/SOPT-iOS/Projects/Domain/Sources/Error/CoreAuthError.swift index 8207987a..c6aca8e5 100644 --- a/SOPT-iOS/Projects/Domain/Sources/Error/CoreAuthError.swift +++ b/SOPT-iOS/Projects/Domain/Sources/Error/CoreAuthError.swift @@ -7,3 +7,19 @@ // import Foundation + +public enum CoreAuthError: Error { + case apple(Apple) + case google(Google) + case unknown(Error) + + public enum Apple: Error { + case authFail(Error) + case credentialFail + case encodedFail + } + + public enum Google: Error { + + } +} diff --git a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/CoreOAuthRepositoryInterface.swift b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/CoreOAuthRepositoryInterface.swift index b0fe39e5..46a19de7 100644 --- a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/CoreOAuthRepositoryInterface.swift +++ b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/CoreOAuthRepositoryInterface.swift @@ -1,5 +1,5 @@ // -// CoreAuthRepository.swift +// CoreOAuthRepositoryInterface.swift // Domain // // Created by 장석우 on 1/18/25. diff --git a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift index 0b7b6a4f..e24cec71 100644 --- a/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift +++ b/SOPT-iOS/Projects/Domain/Sources/RepositoryInterface/SignInRepositoryInterface.swift @@ -8,8 +8,6 @@ import Combine -// TODO: - User 유형 설정 방식 생각하기 - public protocol SignInRepositoryInterface { func requestSignIn(token: String) -> AnyPublisher } diff --git a/SOPT-iOS/Projects/Domain/Sources/UseCase/SignInUseCase.swift b/SOPT-iOS/Projects/Domain/Sources/UseCase/SignInUseCase.swift index f1e0da34..decf52bc 100644 --- a/SOPT-iOS/Projects/Domain/Sources/UseCase/SignInUseCase.swift +++ b/SOPT-iOS/Projects/Domain/Sources/UseCase/SignInUseCase.swift @@ -17,17 +17,25 @@ public enum SiginInHandleableType { public protocol SignInUseCase { func requestSignIn(token: String) + func login(with provider: OAuthType) -> AnyPublisher var signInSuccess: CurrentValueSubject { get set } } public class DefaultSignInUseCase { private let repository: SignInRepositoryInterface + private let oauthRepository: CoreOAuthRepositoryInterface + private var cancelBag = CancelBag() + public var signInSuccess = CurrentValueSubject(.loginFailure) - public init(repository: SignInRepositoryInterface) { + public init( + repository: SignInRepositoryInterface, + oauthRepository: CoreOAuthRepositoryInterface + ) { self.repository = repository + self.oauthRepository = oauthRepository } } @@ -46,4 +54,12 @@ extension DefaultSignInUseCase: SignInUseCase { self.signInSuccess.send(isSuccessed ? .loginSuccess : .loginFailure) }.store(in: self.cancelBag) } + + public func login(with provider: OAuthType) -> AnyPublisher { + oauthRepository.getIdentityToken(from: .apple) + .catch { _ in + return Empty() + } + .eraseToAnyPublisher() + } } diff --git a/SOPT-iOS/Projects/Features/AuthFeature/Sources/Coordinator/AuthBuilder.swift b/SOPT-iOS/Projects/Features/AuthFeature/Sources/Coordinator/AuthBuilder.swift index 026a188b..65011677 100644 --- a/SOPT-iOS/Projects/Features/AuthFeature/Sources/Coordinator/AuthBuilder.swift +++ b/SOPT-iOS/Projects/Features/AuthFeature/Sources/Coordinator/AuthBuilder.swift @@ -13,6 +13,7 @@ import Domain public final class AuthBuilder { @Injected public var repository: SignInRepositoryInterface + @Injected public var oauthRepository: CoreOAuthRepositoryInterface public init() { } } @@ -20,7 +21,7 @@ final class AuthBuilder { extension AuthBuilder: AuthFeatureViewBuildable { public func makeSignIn() -> SignInPresentable { - let useCase = DefaultSignInUseCase(repository: repository) + let useCase = DefaultSignInUseCase(repository: repository, oauthRepository: oauthRepository) let vm = SignInViewModel(useCase: useCase) let vc = SignInVC() vc.viewModel = vm diff --git a/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/ViewModel/SignInViewModel.swift b/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/ViewModel/SignInViewModel.swift index 09a2f015..6d9c75be 100644 --- a/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/ViewModel/SignInViewModel.swift +++ b/SOPT-iOS/Projects/Features/AuthFeature/Sources/SignInScene/ViewModel/SignInViewModel.swift @@ -60,16 +60,13 @@ extension SignInViewModel { UserDefaultKeyList.clearUserData() }.store(in: self.cancelBag) - input.googleLoginButtonTapped + Publishers.Merge( + input.googleLoginButtonTapped.map { OAuthType.google }, + input.appleLoginButtonTapped.map { OAuthType.apple } + ).flatMap(useCase.login) .withUnretained(self) - .sink { owner, _ in - owner.onSocialLoginFail?() //TODO: 구글 로그인 로직 - }.store(in: self.cancelBag) - - input.appleLoginButtonTapped - .withUnretained(self) - .sink { owner, _ in - owner.onSocialLoginFail?() //TODO: 애플 로그인 로직 + .sink { owner, id in + print(id) }.store(in: self.cancelBag) input.signUpButtonTapped diff --git a/SOPT-iOS/Projects/SOPT-iOS/SOPT-iOS.entitlements b/SOPT-iOS/Projects/SOPT-iOS/SOPT-iOS.entitlements index 903def2a..80b5221d 100644 --- a/SOPT-iOS/Projects/SOPT-iOS/SOPT-iOS.entitlements +++ b/SOPT-iOS/Projects/SOPT-iOS/SOPT-iOS.entitlements @@ -4,5 +4,9 @@ aps-environment development + com.apple.developer.applesignin + + Default + diff --git a/SOPT-iOS/Projects/SOPT-iOS/Sources/Dependency/RegisterDependencies.swift b/SOPT-iOS/Projects/SOPT-iOS/Sources/Dependency/RegisterDependencies.swift index 9d343ba4..caf1ae8f 100644 --- a/SOPT-iOS/Projects/SOPT-iOS/Sources/Dependency/RegisterDependencies.swift +++ b/SOPT-iOS/Projects/SOPT-iOS/Sources/Dependency/RegisterDependencies.swift @@ -27,6 +27,14 @@ extension AppDelegate { ) } ) + + container.register( + interface: CoreOAuthRepositoryInterface.self, + implement: { + CoreOAuthRepository(appleService: DefaultAppleAuthenticationService()) + } + ) + container.register( interface: SplashRepositoryInterface.self, implement: {