feat: create authentication-flow.guard

pull/4995/head
mehmet-erim 5 years ago
parent 717f8b68fb
commit bbad96fdc2

@ -10,12 +10,14 @@ import { LoginComponent } from './components/login/login.component';
import { ManageProfileComponent } from './components/manage-profile/manage-profile.component';
import { RegisterComponent } from './components/register/register.component';
import { eAccountComponents } from './enums/components';
import { AuthenticationFlowGuard } from './guards/authentication-flow.guard';
const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: 'login' },
{
path: '',
component: DynamicLayoutComponent,
canActivate: [AuthenticationFlowGuard],
children: [
{
path: 'login',

@ -14,6 +14,7 @@ import { TenantBoxComponent } from './components/tenant-box/tenant-box.component
import { Options } from './models/options';
import { ACCOUNT_OPTIONS } from './tokens/options.token';
import { accountOptionsFactory } from './utils/factory-utils';
import { AuthenticationFlowGuard } from './guards/authentication-flow.guard';
@NgModule({
declarations: [
@ -39,6 +40,7 @@ export class AccountModule {
return {
ngModule: AccountModule,
providers: [
AuthenticationFlowGuard,
{ provide: ACCOUNT_OPTIONS, useValue: options },
{
provide: 'ACCOUNT_OPTIONS',

@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { OAuthService } from 'angular-oauth2-oidc';
@Injectable()
export class AuthenticationFlowGuard implements CanActivate {
constructor(private oauthService: OAuthService) {}
canActivate() {
if (this.oauthService.responseType === 'code') {
this.oauthService.initCodeFlow();
return false;
}
return true;
}
}
Loading…
Cancel
Save