forked from thijooree/android
fix single profile multi login
This commit is contained in:
@@ -429,17 +429,46 @@ class CredentialsFragment : Fragment() {
|
||||
if (anySession != null) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val info = BmlLoginFlow().fetchUserInfo(anySession)
|
||||
if (info != null) store.saveBmlUserProfile(
|
||||
bmlLoginId,
|
||||
CredentialStore.BmlUserProfile(
|
||||
fullName = info.fullName,
|
||||
email = info.email,
|
||||
mobile = info.mobile,
|
||||
customerId = info.customerId,
|
||||
idCard = info.idCard,
|
||||
birthdate = info.birthdate
|
||||
if (info != null) {
|
||||
store.saveBmlUserProfile(
|
||||
bmlLoginId,
|
||||
CredentialStore.BmlUserProfile(
|
||||
fullName = info.fullName,
|
||||
email = info.email,
|
||||
mobile = info.mobile,
|
||||
customerId = info.customerId,
|
||||
idCard = info.idCard,
|
||||
birthdate = info.birthdate
|
||||
)
|
||||
)
|
||||
)
|
||||
// Single-profile accounts used username as a temporary profileId.
|
||||
// Replace it with the real BML customer ID so multi-login doesn't collide.
|
||||
val customerId = info.customerId
|
||||
if (customerId.isNotBlank()) {
|
||||
val profiles = store.loadBmlProfiles(bmlLoginId)
|
||||
val autoProfile = profiles.firstOrNull { it.autoActivated }
|
||||
if (autoProfile != null && autoProfile.profileId != customerId) {
|
||||
val oldId = autoProfile.profileId
|
||||
// Re-key session in memory and storage
|
||||
val session = app.bmlSessions.remove(oldId)
|
||||
if (session != null) {
|
||||
app.bmlSessions[customerId] = session
|
||||
store.clearBmlProfileSession(oldId)
|
||||
store.saveBmlProfileSession(customerId, session.accessToken, session.deviceId)
|
||||
}
|
||||
// Update stored profile list with the real ID
|
||||
val updatedProfiles = profiles.map {
|
||||
if (it.autoActivated) it.copy(profileId = customerId) else it
|
||||
}
|
||||
store.saveBmlProfiles(bmlLoginId, updatedProfiles)
|
||||
app.bmlProfilesMap[bmlLoginId] = updatedProfiles
|
||||
// Update accounts to use real profileId
|
||||
bmlAccumulatedAccounts.replaceAll { acc ->
|
||||
if (acc.profileId == oldId) acc.copy(profileId = customerId) else acc
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user