-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(security): add ability to assign multiple roles to a user (#549)
Closes #222
- Loading branch information
Showing
4 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Assign multiple roles to a user | ||
|
||
In a case when you have a slightly more complicated requirements, when the user have more than one role, you can configure the `NbRoleProvider` service to return an array of user roles. | ||
<hr> | ||
|
||
## Roles configuration | ||
|
||
In a simplest form you just need to modify the `getRole` method to return an array of roles: | ||
```ts | ||
// ... | ||
|
||
import { of as observableOf } from 'rxjs/observable/of'; | ||
import { NbSecurityModule, NbRoleProvider } from '@nebular/security'; | ||
|
||
|
||
@NgModule({ | ||
imports: [ | ||
// ... | ||
|
||
NbSecurityModule.forRoot({ | ||
// ... | ||
}), | ||
|
||
], | ||
providers: [ | ||
// ... | ||
{ | ||
provide: NbRoleProvider, | ||
useValue: { | ||
getRole: () => { | ||
// here we simply return a list of roles for current user | ||
return observableOf(['guest', 'user', 'editor']); | ||
}, | ||
}, | ||
}, | ||
], | ||
``` | ||
Thus, once a user is accessing some secured resource, `isGranted` method returns `true` if at least one of the roles can access the resource. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters