6

I recently created an AWS Mobile hub project with Cognito user pools, When I logged in it remembers the logged in user, once I delete the application (Without login out) and reinstall the application, It automatically login to the previous account, How to prevent that issue ?

P.S - I'm using latest AWS Mobile Hub iOS SDK

Poorna
  • 133
  • 2
  • 7

1 Answers1

7

This occurs because the Cognito framework stores login info in the keychain, which persists even after an app is deleted. One way to fix this is to check if the app is a fresh install on application start and logout of the current user if signed in.

To check for fresh installs & updates in my apps, I usually store the build number in UserDefaults and check to see if it is nil or has changed on application start:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let previousBuild = UserDefaults.standard.string(forKey: "build")
    let currentBuild = Bundle.main.infoDictionary!["CFBundleVersion"] as! String
    if previousBuild == nil {
        //fresh install
        //logout of current user
    } else if previousBuild != currentBuild {
        //application updated
    }
    UserDefaults.standard.set(currentBuild, forKey: "build")

    return true
}
Jake
  • 13,097
  • 9
  • 44
  • 73