Search code examples
androidnativescriptnativescript-vue

back button in android breaks nativescript-vue access control login logout


I have come up with an implementation of access control for a nativescript app but the android back button breaks it.

Scenario:

  1. Open the app
  2. press login
  3. press back button in android (The app will be minimized)
  4. Open the app again (you are supposed to see that you are logged in but you see that you appear to be logged out)
  5. Now actually close the app
  6. Open the app again (You will see that you were actually logged in but the app was displaying the wrong page for you)

How can I fix this issue? What is the propper way to stay logged-in in a nativescript-vue app?

Here is a playground sample


Solution

  • It happens sometimes with global variables, I didn't manage to track how exactly but a hot fix is to use a function.

    function isLoaddedIn() {
        return ApplicationSettings.getString('is_logged_in') == 'true';
    }
    
    new Vue({
        render: h => h('frame', [h(isLoaddedIn() ? In : Out)])
    }).$start()