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