akveo / akveo/nebular

Using accessChecker on parameterized path

Open
#2,559 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
8.1k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### Issue type

**I'm submitting a ...** (check one with "x")

* [x] bug report
* [ ] feature request

### Issue description
I'm using `accessChecker.isGranted()` method in `canActivate()` to check whether the user has access to the route, this doesn't work for route where I pass parameters.

**Current behavior:** `accessChecker.isGranted(permission, resource)` returns `false` on parameterized route path

**Expected behavior:** Detect if path has `parameter`, if yes enable the route.

**Steps to reproduce:**


app.module.ts

NbSecurityModule.forRoot({
accessControl: {
guest: {
view: ['news'],
}
}})

app.routing.ts

const routes: Routes = [
...
{ path: 'news/:newsID', component: BookDetailsComponent, canActivate: [RouteGuard] },
...
];

route.guard.ts

canActivate(...) {
returns this.accessChecker.isGranted('view', route.routeConfig.path).pipe(
map(resolve => {
if(resolve) {
return resolve;
}else{
this.router.navigate(['auth/login']);
return false;
}
}
);
}

### Other information:

**Angular, Nebular**
```
"@angular/common": "~10.1.4",
"@angular/compiler": "~10.1.4",
"@angular/core": "~10.1.4",
"@nebular/auth": "^6.2.1",
"@nebular/eva-icons": "6.2.1",
"@nebular/security": "^6.2.1",
"@nebular/theme": "^6.2.1",
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.