From eb074c00aef8ad34c01a441b89dd77f78fc2506a Mon Sep 17 00:00:00 2001 From: spekulaas Date: Fri, 7 Jan 2022 16:58:13 +0100 Subject: [PATCH] created auth to check if cards are set --- AuthentesApp/src/app/app-routing.module.ts | 5 +++-- AuthentesApp/src/app/services/values.auth.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 AuthentesApp/src/app/services/values.auth.ts diff --git a/AuthentesApp/src/app/app-routing.module.ts b/AuthentesApp/src/app/app-routing.module.ts index 770625a..1c1f951 100644 --- a/AuthentesApp/src/app/app-routing.module.ts +++ b/AuthentesApp/src/app/app-routing.module.ts @@ -1,5 +1,6 @@ import { NgModule } from '@angular/core'; import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; +import { AuthGuard } from './services/values.auth'; const routes: Routes = [ { @@ -12,11 +13,11 @@ const routes: Routes = [ }, { path: 'valuesSorting', - loadChildren: () => import('./valuesSorting/valuesSorting.module').then( m => m.ValuesSortingPageModule) + loadChildren: () => import('./valuesSorting/valuesSorting.module').then( m => m.ValuesSortingPageModule), canActivate: [AuthGuard] }, { path: 'valuesAlign', - loadChildren: () => import('./valuesAlign/valuesAlign.module').then( m => m.ValuesAlignPageModule) + loadChildren: () => import('./valuesAlign/valuesAlign.module').then( m => m.ValuesAlignPageModule), canActivate: [AuthGuard] }, { path: '', diff --git a/AuthentesApp/src/app/services/values.auth.ts b/AuthentesApp/src/app/services/values.auth.ts new file mode 100644 index 0000000..a03b32f --- /dev/null +++ b/AuthentesApp/src/app/services/values.auth.ts @@ -0,0 +1,20 @@ + +import { Injectable } from '@angular/core'; +import { CanActivate, Router } from '@angular/router'; +import { GameService } from './game.service'; + +@Injectable({ + providedIn: 'root' +}) + +export class AuthGuard implements CanActivate { + constructor(private router: Router, private game: GameService) {} + async canActivate(){ + if(this.game.cardset.length > 0){ + return true; + } + // no cards so redirect to the homepage + this.router.navigate(['/home']); + return false; + } +} \ No newline at end of file