Created
March 13, 2023 10:13
-
-
Save tifoaudii/bc9a0b78176a73f5ca2376e38f883931 to your computer and use it in GitHub Desktop.
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
class UserAuthManager { | |
struct UserProfile { | |
let username: String | |
let email: String | |
let phoneNumber: String | |
let gender: String | |
} | |
static let shared: UserAuthManager = UserAuthManager() | |
var userProfile: UserProfile? | |
var isUserLoggedIn: Bool { | |
userProfile != nil | |
} | |
private init() {} | |
func login(with email: String, password: String, completion: @escaping (Result<UserProfile, Error>) -> Void) { | |
SomeLoginProviderService.shared.login(email, password) { [weak self] result in | |
guard let self else { return } | |
switch result { | |
case .success(let user): | |
self.userProfile = UserProfile(username: user.username, email: user.email, phoneNumber: user.phoneNumber, gender: user.gender) | |
completion(.success(self.userProfile)) | |
case .error(let error): | |
completion(.failure(error)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment