diff --git a/src/app/app.component.html b/src/app/app.component.html index fffda4570d71bade9f81cad65fb569efccf59908..b8ca6190b5fae230a0f000e0b02d0178a48eac68 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,6 +1,6 @@ - + Menu diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5da945e5b0583e6019d39e3583f2eaf7b4c865c6..275e9773c38bd9ffe54294ded84e3b31cfe41243 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,6 +3,10 @@ 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'; +import { Storage } from '@ionic/storage'; +import { Router } from '@angular/router'; + +import { RestService } from './rest.service'; @Component({ selector: 'app-root', @@ -10,6 +14,9 @@ import { StatusBar } from '@ionic-native/status-bar/ngx'; styleUrls: ['app.component.scss'] }) export class AppComponent { + + + public appPages = [ { title: 'Home', @@ -26,9 +33,19 @@ export class AppComponent { constructor( private platform: Platform, private splashScreen: SplashScreen, - private statusBar: StatusBar + private statusBar: StatusBar, + public restService: RestService, + private storage: Storage, + private router: Router ) { this.initializeApp(); + this.storage.get('token').then((token) => { + if(token === "") { + this.router.navigateByUrl('/login'); + } else { + this.restService.isUserLoggedIn = true; + } + }); } initializeApp() { diff --git a/src/app/auth/login/login.page.ts b/src/app/auth/login/login.page.ts index 728943133a98bc25b98023d72e4b9c4114292155..5f20f0473bd60546a91d16e0aef75fbf184189f1 100644 --- a/src/app/auth/login/login.page.ts +++ b/src/app/auth/login/login.page.ts @@ -46,7 +46,5 @@ export class LoginPage implements OnInit { } register() { this.router.navigateByUrl('/register'); - - } } diff --git a/src/app/rest.service.ts b/src/app/rest.service.ts index d0156233b399fbc65a643732c5c365fcde495c5f..e6e4ac6214b6a8a9e423d2ac835980f9a8069930 100644 --- a/src/app/rest.service.ts +++ b/src/app/rest.service.ts @@ -6,11 +6,13 @@ import { Storage } from '@ionic/storage'; }) export class RestService { + public isUserLoggedIn = false; + constructor(private storage: Storage) { } setToken(token) { - // set a key/value this.storage.set('token', token); + this.isUserLoggedIn = true; } getToken() {