dev smartfarming #1
|
|
@ -3,7 +3,7 @@ import { DashboardComponent } from './pages/dashboard/dashboard.component';
|
||||||
import { LayoutsComponent } from './pages/dashboard/layouts/layouts.component';
|
import { LayoutsComponent } from './pages/dashboard/layouts/layouts.component';
|
||||||
import { GraphComponent } from './pages/dashboard/page/graph/graph.component';
|
import { GraphComponent } from './pages/dashboard/page/graph/graph.component';
|
||||||
import { AuthComponent } from './pages/auth/auth.component';
|
import { AuthComponent } from './pages/auth/auth.component';
|
||||||
import { AuthGuard } from './cores/guard/guards/auth.guard';
|
import { AuthGuard } from './cores/guards/auth.guard';
|
||||||
import { RegisterComponent } from './pages/register/register.component';
|
import { RegisterComponent } from './pages/register/register.component';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import { TestBed } from '@angular/core/testing';
|
|
||||||
import { CanActivateFn } from '@angular/router';
|
|
||||||
|
|
||||||
import { authGuard } from './auth.guard';
|
|
||||||
|
|
||||||
describe('authGuard', () => {
|
|
||||||
const executeGuard: CanActivateFn = (...guardParameters) =>
|
|
||||||
TestBed.runInInjectionContext(() => authGuard(...guardParameters));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.configureTestingModule({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be created', () => {
|
|
||||||
expect(executeGuard).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CanActivate, Router } from '@angular/router';
|
import { CanActivate, Router } from '@angular/router';
|
||||||
|
import { ToastrService } from 'ngx-toastr';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthGuard implements CanActivate {
|
export class AuthGuard implements CanActivate {
|
||||||
|
|
||||||
constructor(private router: Router) {}
|
constructor(private router: Router, private toast: ToastrService) {}
|
||||||
|
|
||||||
canActivate(): boolean {
|
canActivate(): boolean {
|
||||||
const token = localStorage.getItem('accessToken');
|
const token = localStorage.getItem('accessToken');
|
||||||
if (token) {
|
if (token) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
this.toast.error('You need to login first');
|
||||||
this.router.navigate(['auth']);
|
this.router.navigate(['auth']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user