question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ngx-permissions - NgxPermissionsGuard routing issue redirect to default route.

See original GitHub issue

Current behavior

We have 3 child route and 1 root route

  1. oneadmin/login
  2. twoadmin/login
  3. site/login
  4. app route for root and lazy loading

I used to build angular 4 application with nodejs we have 2 admin panel, 1 site and app.module.ts we used for lazy loading, ngx-permissions, NgxPermissionsGuard.

After the user login from oneadmin they can access every route but if user is in dashboard user can’t able to refresh page, if user refresh page it’s redirect to http://127.0.0.1:3000.

http://127.0.0.1:3000/oneadmin/dashboard http://127.0.0.1:3000/oneadmin/profile

here is route code

const oneadminroutes: Routes = [ 
  {
    path: 'oneadmin', pathMatch: 'full', redirectTo: 'oneadmin/login',
  },
  {
    path: 'oneadmin/login', component: LoginComponent,
  },
  {
    path: 'oneadmin',
    component: OneAdminComponent,
    pathMatch: 'prefix',
    children: [
      {
        path: 'dashboard',
        component: DashboardComponent,
        pathMatch: 'prefix',
        canActivate: [NgxPermissionsGuard],
        data: {
          permissions: { only: ['role1', 'role2', 'role3'] }
        }
      },
      {
        path: 'profile',
        component: UserProfileComponent,
        canActivate: [NgxPermissionsGuard],
        data: {
          permissions: { only: ['role1', 'role2', 'role3']  }
        }
      },
 ]
  }
];
export const OneadminRoutingModule: ModuleWithProviders = RouterModule.forChild(oneadminroutes);

Expected behavior

if user refresh the page it want redirect to to anywhere just stay them in to current page. http://127.0.0.1:3000/oneadmin/dashboard

Environment


Angular version :
Angular CLI: 1.6.1
Node: 8.9.1
OS: linux ia32
Angular: 5.1.1
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cli: 1.6.1
@angular/language-service: 4.4.6
@angular/tsc-wrapped: 4.4.6
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.1
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.6.2
webpack: 3.10.0

ngx-permissions version: ^3.0.0

Browser:
- [ ] Chromium (Ubuntu desktop) : version Version 62.0.3202.89 (Official Build) Built on Ubuntu , running on Ubuntu 16.04 (32-bit)
- [ ] Firefox version (Ubuntu desktop) : 57.0.1 (32-bit)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexKhymenkocommented, Jan 26, 2018

So the problem is. When user logins you assign permissions everything is good. But then you refresh and the whole data is lost including permissions. The user triest to access the page. Router checkes the permissions for him to view the page. There are no permissions there. User redirects to another page.

So You need to save permissions on login to localStorate. And before app starts load them to ngxPermissionsService again. https://www.intertech.com/Blog/angular-4-tutorial-run-code-during-app-initialization/

0reactions
kishansiliconinfocommented, Jan 26, 2018

No i don’t have this permission on starting on the app. assigning permission after user login

Read more comments on GitHub >

github_iconTop Results From Across the Web

Usage with routes · AlexKhymenko/ngx-permissions Wiki
Single redirection rule​​ In case you want to redirect to some specific state when user is not authorized pass to redirectTo path of...
Read more >
NgxPermissions not working with Lazy Loaded Module
But ngx-permissions functionality is neither working for routing using NgxPermissionsGuard nor for elements using *ngxPermissionsOnly.
Read more >
Route Redirect Issue - Server Fault
I have two routers in the same subnet: ... All client machines have the Linux server as a default gateway. The Linux server...
Read more >
Ngx-permissions Tutorial #6 - Create custom guard ... - YouTube
Ngx-permissions angular tutorial. This is example how to create your custom guard by extending ngxPermissionsGuard.0:00 Use case0:44 ...
Read more >
ngx-permissions - Bountysource
Created 17 days ago in AlexKhymenko/ngx-permissions with 1 comments. ... new release) [x] Bug report [ ] Feature request [ ] Documentation issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found