kri*_*dev 3 jwt passport.js nestjs passport-jwt
我是 Nestjs 的新手,我已经使用他的相关 AuthGuard 设置了一个“jwt”PassportStrategy,现在我必须创建一个完全不同的“jwt”PassportStrategy 和他的相关 AuthGuard,我该怎么做?你有什么例子吗?
小智 5
首先,您创建另一个策略类。扩展基本 PassportStrategy 时的第二个参数将是您的策略的名称,您可以将其与 AuthGuard 一起使用来指定它将使用哪个策略。
export class OtherStrategy extends PassportStrategy(Strategy, 'other-strategy')
{ STRATEGY IMPLEMENTATION }
Run Code Online (Sandbox Code Playgroud)
然后你可以在你的控制器中使用它,比如
@UseGuards(AuthGuard('other-strategy')
@Post('/my-endpoint')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
738 次 |
| 最近记录: |