Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Best way to check login globally in Ionic 2

$
0
0

@newelement wrote:

Greetings gals and guys. I'm trying to figure out the best way to globally check for authenticated user. Here's my app.js and auth provider files. Looking for help/feedback on best way to do this:

app.js

import 'es6-shim';
import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {Page1} from './pages/page1/page1';
import {LoginPage} from './pages/login/login';
import {AuthService} from './providers/auth-service/auth-service';


@App({
  template: '<ion-nav [root]="rootPage"></ion-nav>',
  config: {},
  providers: [AuthService]
})
export class MyApp {
  static get parameters() {
return [[Platform], [AuthService]];
}

constructor(platform, auth) {

 if( !auth.login() ){
     this.rootPage = LoginPage;
 } else {
     this.rootPage = Page1;
}

platform.ready().then(() => {
  StatusBar.styleDefault();
});
  }
}

auth-service.js

import 'es6-shim';
import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {Page1} from './pages/page1/page1';
import {LoginPage} from './pages/login/login';
import {AuthService} from './providers/auth-service/auth-service';


@App({
  template: '<ion-nav [root]="rootPage"></ion-nav>',
  config: {},
  providers: [AuthService]
})
export class MyApp {
  static get parameters() {
    return [[Platform], [AuthService]];
  }

 constructor(platform, auth) {

 if( !auth.login() ){
     this.rootPage = LoginPage;
 } else {
     this.rootPage = Page1;
}

platform.ready().then(() => {
  StatusBar.styleDefault();
});
}
}

Posts: 5

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>