Created
August 18, 2017 20:56
-
-
Save Herakleis/914fcbba73c4f007d85dbe6cac245765 to your computer and use it in GitHub Desktop.
Singleton+Template
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
import RxSwift | |
import RxSwiftExt | |
enum AuthenticationStatus { | |
case none | |
case error(AuthServiceError) | |
case user(String) | |
} | |
final class AuthManager { | |
let status = Variable(AuthenticationStatus.none) | |
static let shared = AuthManager() | |
private let authService = AuthService() | |
private init() { } | |
func signUpUserWith(email: String, password: String) -> Observable<UserAuthResult> { | |
return authService.signUpUserWith(email: email, password: password) | |
} | |
func signInUserWith(email: String, password: String) -> Observable<UserAuthResult> { | |
return authService.signInUserWith(email: email, password: password) | |
} | |
func signOutUser() -> Observable<UserAuthResult> { | |
return authService.signOut() | |
} | |
func currentUserId() -> Observable<String> { | |
return self.status.asObservable() | |
.filterMap { authStatus -> FilterMap<String> in | |
switch authStatus { | |
case .user(let userId): | |
return .map(userId) | |
default: | |
return .ignore | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment