Skip to content

Commit

Permalink
fix: 로그인 시 메인화면 진입 못하는 이슈 수정해요 (#665)
Browse files Browse the repository at this point in the history
* fix: AccountSignInViewController 기존 ShowNextPage  코드 제거
- AccountSignInReactor meUseCase 및 SignInNavigator 추가
- OnboardingReactor updateIsFirstOnboardingUseCase 추가

* fix: AccountSignInReactor 화면 전환 로직 수정
- AccountResignViewReactor 회원 탈퇴시 isFirstOnboarding false 값으로 수정
- FetchIsFirstOnboardingUseCase 예외 처리 로직 추가
- AppUserDefaults 로직 수정

* fix: print구문 제거
  • Loading branch information
Do-hyun-Kim authored Sep 30, 2024
1 parent 91ccdef commit 29bdaa4
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protocol AccountSignInNavigatorProtocol: BaseNavigator {
func toMain()
func toSignUp()
func toJoinFamily()
func toOnboarding()
}

final class AccountSignInNavigator: AccountSignInNavigatorProtocol {
Expand All @@ -37,4 +38,9 @@ final class AccountSignInNavigator: AccountSignInNavigatorProtocol {
let vc = JoinFamilyViewControllerWrapper().viewController
navigationController.setViewControllers([vc], animated: false)
}

func toOnboarding() {
let vc = OnboardingViewControllerWrapper().viewController
navigationController.setViewControllers([vc], animated: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public final class AccountSignInReactor: Reactor {
public var initialState: State
@Injected var fetchIsFirstOnboardingUseCase: any FetchIsFirstOnboardingUseCaseProtocol
private var accountRepository: AccountImpl = AccountRepository()
private let meUseCase: MeUseCaseProtocol = MeUseCase(meRepository: MeAPIs.Worker())
private let fcmUseCase: FCMUseCaseProtocol = FCMUseCase(FCMRepository: MeAPIs.Worker())
@Navigator var signInNavigator: AccountSignInNavigatorProtocol
private let disposeBag = DisposeBag()

public enum Action {
Expand All @@ -26,59 +28,49 @@ public final class AccountSignInReactor: Reactor {
}

public enum Mutation {
case kakaoLogin(Bool)
case appleLogin(Bool)
case setIsFirstOnboarding(Bool)

}

public struct State {
var pushAccountSingUpVC: Bool
@Pulse var isFirstOnboarding: Bool
}

init(/*accountRepository: AccountRepository, fcmUseCase: FCMUseCaseProtocol*/) {
// self.accountRepository = accountRepository
// self.fcmUseCase = fcmUseCase
self.initialState = State(
pushAccountSingUpVC: false,
isFirstOnboarding: false
)
}
}

extension AccountSignInReactor {
public func mutate(action: Action) -> Observable<Mutation> {
let isFirstOnboarding = self.fetchIsFirstOnboardingUseCase.execute() == nil ? false : true
switch action {
case .kakaoLoginTapped(let sns, let vc):
return accountRepository.kakaoLogin(with: sns, vc: vc)
.flatMap { result -> Observable<Mutation> in
.withUnretained(self)
.flatMap { owner, result -> Observable<Mutation> in
switch result {
case .success:
self.saveFCM()
return .concat(
.just(.kakaoLogin(true)),
.just(.setIsFirstOnboarding(isFirstOnboarding))
)
owner.saveFCM()
return owner.transitionViewController()
case .failed:
return .just(.kakaoLogin(false))
return .empty()
}
}


case .appleLoginTapped(let sns, let vc):
return accountRepository.appleLogin(with: sns, vc: vc)
.flatMap { result -> Observable<Mutation> in
.withUnretained(self)
.flatMap { owner, result -> Observable<Mutation> in
switch result {
case .success:
self.saveFCM()
return .concat(
.just(.appleLogin(true)),
.just(.setIsFirstOnboarding(isFirstOnboarding))
)
return owner.transitionViewController()
case .failed:
return .just(.appleLogin(false))
return .empty()
}
}
}
Expand All @@ -87,10 +79,6 @@ extension AccountSignInReactor {
public func reduce(state: State, mutation: Mutation) -> State {
var newState = state
switch mutation {
case .kakaoLogin(let result):
newState.pushAccountSingUpVC = result
case .appleLogin(let result):
newState.pushAccountSingUpVC = result
case let .setIsFirstOnboarding(isFirstOnboarding):
newState.isFirstOnboarding = isFirstOnboarding
}
Expand All @@ -112,3 +100,40 @@ extension AccountSignInReactor {
}
}
}


extension AccountSignInReactor {
private func transitionViewController() -> Observable<Mutation> {
let isFirstOnboarding = self.fetchIsFirstOnboardingUseCase.execute()
return App.Repository.token.accessToken
.skip(1)
.withUnretained(self)
.flatMapLatest { owner, token -> Observable<Mutation> in
guard let token,
let isTemporaryToken = token.isTemporaryToken else {
return .empty()
}

if isTemporaryToken {
owner.signInNavigator.toSignUp()
return .empty()
}

return owner.meUseCase.getMemberInfo()
.asObservable()
.flatMap { memberInfo -> Observable<Mutation> in
if isFirstOnboarding {
if memberInfo?.familyId == nil {
owner.signInNavigator.toJoinFamily()
return .empty()
}
owner.signInNavigator.toMain()
return .empty()
}
owner.signInNavigator.toOnboarding()
return .empty()
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,39 +129,6 @@ public final class AccountSignInViewController: BaseViewController<AccountSignIn
.map { Reactor.Action.appleLoginTapped(.apple, self) }
.bind(to: reactor.action)
.disposed(by: disposeBag)


Observable
.combineLatest(
App.Repository.token.accessToken.distinctUntilChanged(),
reactor.pulse(\.$isFirstOnboarding).distinctUntilChanged()
)
.skip(1)
.observe(on: RxScheduler.main)
.bind(with: self) { owner, response in
let (token, isFirstOnboarding) = response
owner.showNextPage(token: token, isFirstOnboarding)
}
.disposed(by: disposeBag)
}
}

extension AccountSignInViewController {
private func showNextPage(token: AccessToken?, _ isFirstOnboarding: Bool) {
@Navigator var signInNavigator: AccountSignInNavigatorProtocol
guard let token = token, let isTemporaryToken = token.isTemporaryToken else { return }
if isTemporaryToken {
signInNavigator.toSignUp()
return
}

if isFirstOnboarding || isTemporaryToken == false {
if App.Repository.member.familyId.value == nil {
signInNavigator.toJoinFamily()
return
}
signInNavigator.toMain()
return
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ final class MainViewReactor: Reactor {
@Injected var fetchMainUseCase: FetchMainUseCaseProtocol
@Injected var fetchMainNightUseCase: FetchNightMainViewUseCaseProtocol
@Injected var pickUseCase: PickUseCaseProtocol
@Injected var updateIsFirstOnboardingUseCase: any UpdateIsFirstOnboardingUseCaseProtocol
@Injected var checkMissionAlertShowUseCase: CheckMissionAlertShowUseCaseProtocol
@Injected var checkFamilyManagementUseCase: FetchIsFirstFamilyManagementUseCaseProtocol
@Injected var saveFamilyManagementUseCase: UpdateFamilyManagementUseCaseProtocol
Expand Down Expand Up @@ -170,7 +169,6 @@ extension MainViewReactor {
}
case .calculateTime:
let (isInTime, time) = self.calculateRemainingTime()
self.updateIsFirstOnboardingUseCase.execute(true)
if isInTime {
return Observable.concat([
.just(.setInTime(true)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class OnBoardingReactor: Reactor {

public var initialState: State = State()
@Injected var familyUseCase: FamilyUseCaseProtocol
@Injected var updateIsFirstOnboardingUseCase: any UpdateIsFirstOnboardingUseCaseProtocol

public enum Action {
case permissionTapped
Expand All @@ -40,7 +41,8 @@ extension OnBoardingReactor {
public func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .permissionTapped:
Observable.create { observer in
Observable.create { [weak self] observer in
self?.updateIsFirstOnboardingUseCase.execute(true)
MPEvent.Account.invitedGroupFinished.track(with: nil)
UNUserNotificationCenter.current().requestAuthorization(
options: [.alert, .badge, .sound],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class AccountResignViewReactor: Reactor {
.withUnretained(self)
.flatMap { owner, entity -> Observable<Mutation> in
if entity.isSuccess {
owner.updateIsFirstOnboardingUseCase.execute(nil)
owner.updateIsFirstOnboardingUseCase.execute(false)
return .concat(
.just(.setLoading(true)),
.just(.setResignEntity(entity.isSuccess)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension MyRepository {
}

public func updateIsFirstOnboarding(_ isFirstOnboarding: Bool?) {
appUserDefaults.saveIsFirstOnboarding(isFirstOnboarding)
return appUserDefaults.saveIsFirstOnboarding(isFirstOnboarding)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ final public class AppUserDefaults: AppUserDefaultsType {
}

public func loadIsFirstOnboarding() -> Bool? {
guard let isFirstOnboarding: Bool = userDefaults[.isFirstOnboarding] else {
return nil
}
return isFirstOnboarding
return userDefaults[.isFirstOnboarding]
}

// MARK: - FamilyManagement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation


public protocol FetchIsFirstOnboardingUseCaseProtocol {
func execute() -> Bool?
func execute() -> Bool
}


Expand All @@ -21,7 +21,10 @@ public final class FetchIsFirstOnboardingUseCase: FetchIsFirstOnboardingUseCaseP
self.myRepository = myRepository
}

public func execute() -> Bool? {
return myRepository.fetchIsFirstOnboarding()
public func execute() -> Bool {
guard let isFirstOnboarding = myRepository.fetchIsFirstOnboarding() else {
return false
}
return isFirstOnboarding
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation


public protocol UpdateIsFirstOnboardingUseCaseProtocol {
func execute(_ isFirstOnboarding: Bool?)
func execute(_ isFirstOnboarding: Bool)
}

public final class UpdateIsFirstOnboardingUseCase: UpdateIsFirstOnboardingUseCaseProtocol {
Expand All @@ -20,7 +20,7 @@ public final class UpdateIsFirstOnboardingUseCase: UpdateIsFirstOnboardingUseCas
self.myRepository = myRepository
}

public func execute(_ isFirstOnboarding: Bool?) {
public func execute(_ isFirstOnboarding: Bool) {
myRepository.updateIsFirstOnboarding(isFirstOnboarding)
}
}

0 comments on commit 29bdaa4

Please sign in to comment.