Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Ionic 2 auth - Skip login page if there's an user on local storage

I have an Ionic 2 application that does an authentication on my Rails 5 backend. Once the user is logged, I store his informations on local storage. So, once the user open the apps and he has already logged before, the login page should be skipped. I'm trying to do that on my app.component setting my root page depending on if there's information about the user on local storage or not, but the storage.get method appears to be asynchronous, so it is executing after my check, so it's always considering it false.

Any ideas how I could fix that?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can set the root page after getting the value from the storage like this:

@Component({
    templateUrl: 'app.html'
})
export class MyApp {
    @ViewChild(Nav) navCtrl: Nav;

    public rootPage; // Just declare the property, don't set a value here

    constructor(...) {
      this.platform.ready().then(() => {
        Splashscreen.hide();

        // Get the status from the storage
        this.storage.get('login:status').then(loggedIn => {
          this.rootPage = loggedIn ? HomePage : LoginPage;
        });
      });
    }

}

In this case, if the user is already logged in, the root page will be the HomePage, and if it's not logged in, the LoginPage.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!