Search code examples
iossessionauthenticationremember-me

How to remember login status in an iOS app with a Node.js backend


I'm making a social iOS app. In order to "remember" user's login status, what I did so far:

  1. for the first time the user logs in/create a new account, the app saves his/her username and password in keychain, and next time when the app launches, in

    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // submit login
    

    }

    the app submits the username/password in keychain to login the user automatically;

  2. In nodejs I set the session expiration time to be 2 hours.

Now suppose after the app launches and automatic login happens, if the app entered background for a long time(longer than 2 hours) and then switch back to foreground, is the user NO LONGER logged in?

If the login status is gone, how can I remain the login status? What I can think of is to add another automatic login logic in

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // submit login
}

But wouldn't that be too much data transmission involved?

Or maybe I can set a permanent session time on the server side? Is that even possible?


Solution

  • Best way to achieve this functionality is to generate a token key for mobile device which can be expire in a long time, you can keep it alive like for 30 days and only invalidate until user logout manually.