Commit 0518f7a0 authored by Jose Blaya's avatar Jose Blaya
Browse files

Refactor the process to update the auth token

parent 701f3edf
......@@ -21,7 +21,8 @@ extension AccountProvider {
//Disconnect the VPN (if it's trying to reconnect)
forceRefreshToken = true
if !Client.providers.vpnProvider.isVPNConnected {
if Client.providers.vpnProvider.vpnStatus == .connecting ||
Client.providers.vpnProvider.vpnStatus == .disconnecting {
Client.providers.vpnProvider.disconnect({ [weak self] error in
guard let _ = error as? ClientError else {
self?.refreshAccount(force: forceRefreshToken)
......
......@@ -119,7 +119,7 @@ class AppPreferences {
}
private func refreshAPIToken() {
if Client.providers.accountProvider.isLoggedIn {
if Client.preferences.authMigrationSuccess == false {
Client.providers.accountProvider.refreshAndLogoutUnauthorized(force: true)
}
}
......@@ -138,18 +138,17 @@ class AppPreferences {
defaults.removeObject(forKey: "LoggedUsername")
defaults.synchronize()
}
refreshAPIToken()
}
func migrate() {
let oldVersion = defaults.string(forKey: Entries.version)
defaults.set(AppPreferences.currentVersion, forKey: Entries.version)
guard (oldVersion == nil) else {
if oldVersion == "4.0" {
refreshAPIToken()
} else if oldVersion != "4.0" && oldVersion != AppPreferences.currentVersion {
if oldVersion != AppPreferences.currentVersion ||
!Client.preferences.authMigrationSuccess { //First time for each update or if the auth token has not been updated
migrateAPItoV2()
refreshAPIToken()
}
return
}
......
......@@ -42,14 +42,14 @@ class Bootstrapper {
// Load the database first
Client.database = Client.Database(team: AppConstants.teamId, group: AppConstants.appGroup)
AppPreferences.shared.migrate()
// Check if should clean the account after delete the app and install again
if Client.providers.accountProvider.shouldCleanAccount {
//If first install, we need to ensure we don't have data from previous sessions in the Secure Keychain
Client.providers.accountProvider.cleanDatabase()
}
AppPreferences.shared.migrate()
// PIALibrary
guard let bundledRegionsURL = AppConstants.Regions.bundleURL else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment