app.component.ts 1.41 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
  isLoginPage = false;
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
    private statusBar: StatusBar,
    public restService: RestService,
    private storage: Storage,
39
40
    private router: Router) {

Rron Jahja's avatar
Rron Jahja committed
41
    this.initializeApp();
42
43
44
45
46
47
48

    let href = window.location.pathname
    if(href === "/login") {
      this.restService.isLoginPage = true;
    } else {
      this.restService.isLoginPage = false;
    }
49
50
51
52
53
54
55
    this.storage.get('token').then((token) => {
      if(token === "") {
        this.router.navigateByUrl('/login');
      } else {
        this.restService.isUserLoggedIn = true;
      }
    });
Rron Jahja's avatar
Rron Jahja committed
56
57
58
59
60
61
62
63
64
  }

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