Commit 1ef6d94e authored by Jose Blaya's avatar Jose Blaya
Browse files

Migrate existing users with a valid token

parent 4a13bdd1
......@@ -13,18 +13,19 @@ import SwiftyBeaver
private let log = SwiftyBeaver.self
extension AccountProvider {
func refreshAndLogoutUnauthorized() {
guard let accountInfo = Client.providers.accountProvider.currentUser?.info else {
return
}
guard accountInfo.isExpired else {
//if not expired we do not need to refresh the token
return
func refreshAndLogoutUnauthorized(force: Bool = false) {
if !force {
guard let accountInfo = Client.providers.accountProvider.currentUser?.info else {
return
}
guard accountInfo.isExpired else {
//if not expired we do not need to refresh the token
return
}
}
refreshAccountInfo { (info, error) in
refreshAccountInfo(force: force, { (info, error) in
guard let error = error as? ClientError else {
return
}
......@@ -35,6 +36,7 @@ extension AccountProvider {
log.error("Account: Failed to refresh account info, user is unauthorized. Logging out...")
self.logout(nil)
}
}
})
}
}
......@@ -32,7 +32,7 @@ class AppPreferences {
static let shared = AppPreferences()
private static let currentVersion = "4.0"
private static let currentVersion = "5.0"
private let defaults: UserDefaults
......@@ -118,6 +118,12 @@ class AppPreferences {
])
}
private func refreshAPIToken() {
if Client.providers.accountProvider.isLoggedIn {
Client.providers.accountProvider.refreshAndLogoutUnauthorized(force: true)
}
}
private func migrateAPItoV2() {
// Migrate users from v1 to v2
log.debug("Migration to api v2")
......@@ -137,9 +143,11 @@ class AppPreferences {
func migrate() {
let oldVersion = defaults.string(forKey: Entries.version)
defaults.set(AppPreferences.currentVersion, forKey: Entries.version)
guard (oldVersion == nil) else {
if oldVersion != "4.0" {
if oldVersion == "4.0" {
refreshAPIToken()
} else if oldVersion != "4.0" && oldVersion != AppPreferences.currentVersion {
migrateAPItoV2()
}
return
......
......@@ -38,7 +38,10 @@ class Bootstrapper {
console.minLevel = .info
#endif
SwiftyBeaver.addDestination(console)
// Load the database first
Client.database = Client.Database(team: AppConstants.teamId, group: AppConstants.appGroup)
AppPreferences.shared.migrate()
// PIALibrary
......@@ -84,8 +87,6 @@ class Bootstrapper {
Client.configuration.setPlan(.yearly, forProductIdentifier: AppConstants.InApp.yearlyProductIdentifier)
Client.configuration.setPlan(.monthly, forProductIdentifier: AppConstants.InApp.monthlyProductIdentifier)
Client.database = Client.Database(team: AppConstants.teamId, group: AppConstants.appGroup)
if (isSimulator || Flags.shared.usesMockVPN) {
Client.configuration.enablesConnectivityUpdates = false
Client.useMockVPNProvider()
......
......@@ -53,7 +53,7 @@ end
def shared_main_pods
pod 'AlamofireImage'
#library_by_path('')
library_by_git('49f14db')
library_by_git('dd71780')
#library_by_version('~> 1.1.3')
end
......
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