Skip to content

Commit 480a90b

Browse files
authored
feat(security): add security setup (#1565)
1 parent f4cdf4a commit 480a90b

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/app/@core/core.module.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { NbAuthModule, NbDummyAuthProvider } from '@nebular/auth';
4+
import { NbSecurityModule, NbRoleProvider } from '@nebular/security';
5+
import { of as observableOf } from 'rxjs/observable/of';
46

57
import { throwIfAlreadyLoaded } from './module-import-guard';
68
import { DataModule } from './data/data.module';
@@ -21,6 +23,27 @@ const NB_CORE_PROVIDERS = [
2123
},
2224
},
2325
}).providers,
26+
NbSecurityModule.forRoot({
27+
accessControl: {
28+
guest: {
29+
view: '*',
30+
},
31+
user: {
32+
parent: 'guest',
33+
create: '*',
34+
edit: '*',
35+
remove: '*',
36+
},
37+
},
38+
}).providers,
39+
{
40+
provide: NbRoleProvider,
41+
useValue: {
42+
getRole: () => {
43+
return observableOf('guest'); // here you could provide any role based on any auth flow
44+
},
45+
},
46+
},
2447
AnalyticsService,
2548
];
2649

src/app/@theme/components/header/header.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[class.right]="position === 'normal'"
1515
[class.left]="position === 'inverse'">
1616
<nb-action icon="nb-grid-b" class="toggle-layout" (click)="toggleSettings()"></nb-action>
17-
<nb-action>
17+
<nb-action *nbIsGranted="['view', 'user']" >
1818
<nb-user [nbContextMenu]="userMenu" [name]="user?.name" [picture]="user?.picture"></nb-user>
1919
</nb-action>
2020
<nb-action class="control-item" disabled icon="nb-notifications"></nb-action>

src/app/@theme/theme.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
NbContextMenuModule,
2020
} from '@nebular/theme';
2121

22+
import { NbSecurityModule } from '@nebular/security';
23+
2224
import {
2325
FooterComponent,
2426
HeaderComponent,
@@ -53,6 +55,7 @@ const NB_MODULES = [
5355
NbPopoverModule,
5456
NbContextMenuModule,
5557
NgbModule,
58+
NbSecurityModule, // *nbIsGranted directive
5659
];
5760

5861
const COMPONENTS = [

src/app/pages/dashboard/dashboard.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NgModule } from '@angular/core';
2+
23
import { NgxEchartsModule } from 'ngx-echarts';
34

45
import { ThemeModule } from '../../@theme/theme.module';

0 commit comments

Comments
 (0)