From a98605a185136391573f68bf2241435b521d11f8 Mon Sep 17 00:00:00 2001 From: Drew Ansbacher Date: Thu, 6 Jan 2022 13:02:01 -0700 Subject: [PATCH] nav guard bugfix (#1037) Co-authored-by: Drew Ansbacher --- setup-wizard/src/app/app-routing.module.ts | 4 ++-- setup-wizard/src/app/guards/nav-guard.ts | 21 +++++++++++++++++++ .../src/app/services/api/mock-api.service.ts | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/setup-wizard/src/app/app-routing.module.ts b/setup-wizard/src/app/app-routing.module.ts index dbfa28561..aeeb38be1 100644 --- a/setup-wizard/src/app/app-routing.module.ts +++ b/setup-wizard/src/app/app-routing.module.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core' import { PreloadAllModules, RouterModule, Routes } from '@angular/router' -import { NavGuard } from './guards/nav-guard' +import { NavGuard, RecoveryNavGuard } from './guards/nav-guard' const routes: Routes = [ { path: '', redirectTo: '/product-key', pathMatch: 'full' }, @@ -21,7 +21,7 @@ const routes: Routes = [ { path: 'recover', loadChildren: () => import('./pages/recover/recover.module').then( m => m.RecoverPageModule), - canActivate: [NavGuard], + canActivate: [RecoveryNavGuard], }, { path: 'embassy', diff --git a/setup-wizard/src/app/guards/nav-guard.ts b/setup-wizard/src/app/guards/nav-guard.ts index e633f93c8..893c7ebf2 100644 --- a/setup-wizard/src/app/guards/nav-guard.ts +++ b/setup-wizard/src/app/guards/nav-guard.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core' import { CanActivate, Router } from '@angular/router' import { HttpService } from '../services/api/http.service' +import { StateService } from '../services/state.service' @Injectable({ providedIn: 'root', @@ -20,3 +21,23 @@ export class NavGuard implements CanActivate { } } } + +@Injectable({ + providedIn: 'root', +}) +export class RecoveryNavGuard implements CanActivate { + constructor ( + private readonly router: Router, + private readonly httpService: HttpService, + private readonly stateService: StateService, + ) { } + + canActivate (): boolean { + if (this.httpService.productKey || !this.stateService.hasProductKey) { + return true + } else { + this.router.navigateByUrl('product-key') + return false + } + } +} diff --git a/setup-wizard/src/app/services/api/mock-api.service.ts b/setup-wizard/src/app/services/api/mock-api.service.ts index f9b609763..c96f7ea5c 100644 --- a/setup-wizard/src/app/services/api/mock-api.service.ts +++ b/setup-wizard/src/app/services/api/mock-api.service.ts @@ -18,7 +18,7 @@ export class MockApiService extends ApiService { async getStatus () { await pauseFor(1000) return { - 'product-key': true, + 'product-key': false, migrating: false, } }