Skip to content

Commit 081be32

Browse files
committed
Fixed overriding username on each login after bio login issue fixed
1 parent 19ca02d commit 081be32

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

GoInfoGame/GoInfoGame/Login/SessionManager.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
import Foundation
99

10-
@MainActor
10+
//@MainActor
1111
final class SessionManager: ObservableObject {
1212
static let shared = SessionManager()
1313
private init() {}
1414

1515
@Published var isLoginSuccessful: Bool = false
1616
@Published var hasLoginFailed: Bool = false
17+
private(set) var username: String? = nil
1718

1819
var lastLoginPassword: String?
1920

@@ -29,21 +30,22 @@ final class SessionManager: ObservableObject {
2930
setupType: .login,
3031
modelType: PosmLoginSuccessResponse.self
3132
) { result in
32-
DispatchQueue.main.async {
33+
DispatchQueue.main.async { [weak self] in
3334
switch result {
3435
case .success(let response):
35-
_ = KeychainManager.save(.username, value: username, for: environment)
36+
self?.username = username
3637
_ = KeychainManager.save(key: "accessToken", data: response.accessToken)
37-
self.lastLoginPassword = password
38+
self?.lastLoginPassword = password
3839

39-
self.isLoginSuccessful = true
40-
self.hasLoginFailed = false
40+
self?.isLoginSuccessful = true
41+
self?.hasLoginFailed = false
4142
completion(true, "")
4243

4344
case .failure(let error):
4445
print("Login failed:", error)
45-
self.isLoginSuccessful = false
46-
self.hasLoginFailed = true
46+
self?.username = nil
47+
self?.isLoginSuccessful = false
48+
self?.hasLoginFailed = true
4749
completion(false, "Invalid credentials")
4850
}
4951
}

GoInfoGame/GoInfoGame/UserProfile/ViewModel/UserProfileViewModel.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class UserProfileViewModel: ObservableObject {
3636

3737
func fetchUserProfile() {
3838

39-
let env = APIConfiguration.shared.environment
40-
41-
guard let username = KeychainManager.load(.username, for: env) else { return }
39+
guard let username = SessionManager.shared.username else { return }
4240

4341
if let accessToken = KeychainManager.load(key: "accessToken") {
4442
ApiManager.shared.performRequest(to: .fetchuserProfile(username, accessToken), setupType: .userProfile, modelType: TdeiUserProfile.self) { result in

0 commit comments

Comments
 (0)