Skip to content

Commit

Permalink
allow only portal link load in iframe (#2153)
Browse files Browse the repository at this point in the history
* allow only portal link load in iframe

* Update web/ui/dashboard/src/app/guards/iframe/iframe.guard.ts

Co-authored-by: Raymond Tukpe <[email protected]>

* chore: remove redundant return

---------

Co-authored-by: Raymond Tukpe <[email protected]>
Co-authored-by: Raymond Tukpe <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent 578d403 commit 2c59457
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions web/ui/dashboard/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { IframeGuard } from './guards/iframe/iframe.guard';

const routes: Routes = [
{
path: '',
loadChildren: () => import('./private/private.module').then(m => m.PrivateModule)
loadChildren: () => import('./private/private.module').then(m => m.PrivateModule),
canActivate: [IframeGuard]
},
{
path: 'portal',
Expand Down Expand Up @@ -38,7 +40,8 @@ const routes: Routes = [
},
{
path: '',
loadChildren: () => import('./public/public.module').then(m => m.PublicModule)
loadChildren: () => import('./public/public.module').then(m => m.PublicModule),
canActivate: [IframeGuard]
}
];

Expand Down
16 changes: 16 additions & 0 deletions web/ui/dashboard/src/app/guards/iframe/iframe.guard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { IframeGuard } from './iframe.guard';

describe('IframeGuard', () => {
let guard: IframeGuard;

beforeEach(() => {
TestBed.configureTestingModule({});
guard = TestBed.inject(IframeGuard);
});

it('should be created', () => {
expect(guard).toBeTruthy();
});
});
11 changes: 11 additions & 0 deletions web/ui/dashboard/src/app/guards/iframe/iframe.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';

@Injectable({
providedIn: 'root'
})
export class IframeGuard implements CanActivate {
canActivate(): boolean {
return window.self === window.top;
}
}

0 comments on commit 2c59457

Please sign in to comment.