Angular2 routing canActivate and AuthGuard (JWT) with user role parameter

前端 未结 3 1259
半阙折子戏
半阙折子戏 2020-12-13 03:33

In this exaple project with JWT authentication we se how to allow only authenticated users to some route:

import { RouterConfig } from \'@angular/router\';
i         


        
3条回答
  •  没有蜡笔的小新
    2020-12-13 04:30

    The signature for CanActivate won't allow you to pass a userRole like you want to. https://github.com/angular/angular/blob/2.0.0-rc.4/modules/%40angular/router/src/interfaces.ts#L54

    It's probably best to do separate classes for each of your user role cases. That's the guidance in the official docs too: https://angular.io/docs/ts/latest/api/router/index/CanActivate-interface.html

提交回复
热议问题