app.component.ts 1.22 KB
Newer Older
Rron Jahja's avatar
Rron Jahja committed
1
2
3
4
5
import { Component } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
6
7
8
9
import { Storage } from '@ionic/storage';
import { Router } from '@angular/router';

import { RestService } from './rest.service';
Rron Jahja's avatar
Rron Jahja committed
10
11
12
13
14
15
16

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
17
18
19



Rron Jahja's avatar
Rron Jahja committed
20
21
22
23
24
25
26
  public appPages = [
    {
      title: 'Home',
      url: '/home',
      icon: 'home'
    },
    {
27
28
29
      title: 'Logout',
      url: '/login',
      icon: 'exit'
Rron Jahja's avatar
Rron Jahja committed
30
31
32
33
34
35
    }
  ];

  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
36
37
38
39
    private statusBar: StatusBar,
    public restService: RestService,
    private storage: Storage,
    private router: Router
Rron Jahja's avatar
Rron Jahja committed
40
41
  ) {
    this.initializeApp();
42
43
44
45
46
47
48
    this.storage.get('token').then((token) => {
      if(token === "") {
        this.router.navigateByUrl('/login');
      } else {
        this.restService.isUserLoggedIn = true;
      }
    });
Rron Jahja's avatar
Rron Jahja committed
49
50
51
52
53
54
55
56
57
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }
}