Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
refactor: 로그인 시 UserDataStorage에 id 넣어주는 로직 추가 #82
Browse files Browse the repository at this point in the history
  • Loading branch information
llghdud921 committed Jul 19, 2022
1 parent 2c88ba8 commit 6e599cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Weekand/Weekand/Domain/UseCase/Sign/SignInUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ final class SignInUseCase {
}
.asSingle()
}

func userID() -> Single<String> {
return NetWork.shared.fetch(query: UserSummaryQuery())
.map {
if let user = $0.user {
return user.id
} else {
return UserSummary.defaultData.name
}
}
.asSingle()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ extension SignInViewModel {

self.signInUseCase.login(email: emailText, password: passwordText).subscribe(onSuccess: { tokenData in
UserDataStorage.shared.setAccessToken(token: tokenData.accessToken)
self.userID()
}, onFailure: { _ in
self.coordinator?.showToastMessage()
}, onDisposed: nil)
.disposed(by: disposeBag)
}

private func userID() {
self.signInUseCase.userID().subscribe(onSuccess: { id in
UserDataStorage.shared.setUserID(id: id)
self.coordinator?.showMainScene()
}, onFailure: { _ in
self.coordinator?.showToastMessage()
Expand Down

0 comments on commit 6e599cd

Please sign in to comment.