yandex
loader

please wait

  • Jadav Payeng Jan-07-2019 01:07:54 PM ( 2 months ago )

    how to create the auth in Hybrid ?

  • Riyansh Verma Jan-07-2019 01:09:28 PM ( 2 months ago )

    commad -> ionic g guard auth 

    file -> import { Injectable } from '@angular/core';

    import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';

    import { Observable } from 'rxjs';

    import { Route } from '@angular/compiler/src/core';

     

    @Injectable({

      providedIn: 'root'

    })

    export class AuthGuard implements CanActivate {

     

      constructor(private router : Router){}

      canActivate(

        next: ActivatedRouteSnapshot,

        state: RouterStateSnapshot): Observable | Promise | boolean {

        const loggedIn = Math.random() > 0.5 ? true : false;

        if(!loggedIn){

          this.router.navigate(['/']);

        }

        return loggedIn;

      }

     

    }

Please login

Similar Discussion

Recommended For You