created auth to check if cards are set

This commit is contained in:
Ryan Bakkes 2022-01-07 16:58:13 +01:00
parent 1df3eb3d5e
commit eb074c00ae
2 changed files with 23 additions and 2 deletions

View File

@ -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: '',

View File

@ -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;
}
}