-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into refactor/#114-Onbo…
…arding
- Loading branch information
Showing
8 changed files
with
217 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
HMH_Tuist_iOS/Projects/Features/LoginFeature/Sources/LoginUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// LoginUseCase.swift | ||
// LoginFeature | ||
// | ||
// Created by Seonwoo Kim on 11/8/24. | ||
// Copyright © 2024 HMH-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
import Domain | ||
import Core | ||
|
||
public enum LoginResponseType { | ||
case loginSuccess | ||
case loginFailure | ||
case onboardingNeeded | ||
} | ||
|
||
public protocol LoginUseCaseType { | ||
func login(provider: OAuthProviderType) -> AnyPublisher<LoginResponseType, AuthError> | ||
} | ||
|
||
public final class LoginUseCase: LoginUseCaseType { | ||
|
||
private let repository: AuthRepositoryType | ||
|
||
public init(repository: AuthRepositoryType) { | ||
self.repository = repository | ||
} | ||
|
||
public func login(provider: OAuthProviderType) -> AnyPublisher<LoginResponseType, Domain.AuthError> { | ||
repository.authorize(provider) | ||
.handleEvents(receiveOutput: { socialToken in | ||
UserManager.shared.socialToken = socialToken | ||
}) | ||
.flatMap { [weak self] _ -> AnyPublisher<LoginResponseType, AuthError> in | ||
guard let self = self else { | ||
return Fail(error: AuthError.appleAuthrizeError).eraseToAnyPublisher() | ||
} | ||
|
||
return self.repository.socialLogin(socialPlatform: provider.rawValue) | ||
.map { _ in LoginResponseType.loginSuccess } | ||
.catch { error -> AnyPublisher<LoginResponseType, AuthError> in | ||
switch error { | ||
case .unregisteredUser: | ||
return Just(.onboardingNeeded) | ||
.setFailureType(to: AuthError.self) | ||
.eraseToAnyPublisher() | ||
default: | ||
return Just(.loginFailure) | ||
.setFailureType(to: AuthError.self) | ||
.eraseToAnyPublisher() | ||
} | ||
} | ||
.eraseToAnyPublisher() | ||
} | ||
.eraseToAnyPublisher() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.