0

I have an anonymous passport strategy defined as:

// In anonymous.strategy.ts
import {Strategy} from 'passport-anonymous'
import {PassportStrategy} from '@nestjs/passport'
import {Injectable} from '@nestjs/common'

@Injectable()
export class AnonymousStrategy extends PassportStrategy(Strategy, 'anonymous') {
  constructor() {
    super()
  }

  // Request times out unless this function is enabled
  // authenticate() {
  //  return this.success({})
  //}
}

Which I then added to the AuthGuards() chain in the controller after 'jwt' one:

  @UseGuards(AuthGuard(['jwt', 'anonymous']))
  @Post('/posts')
  createAd(@Req() req: Request, @Body() createPostDto: CreatePostDto) {
    ...
  }

I can't understand why the request times out unless I enable the authenticate() function in the strategy? After all, I don't have to do this for the passport-jwt strategy. Am I missing something? Thank you.

4

1 回答 1

0

当我将 User 对象添加到成功方法中时,它对我有用。

  authenticate() {
    return this.success(new User());
  }
于 2020-02-05T11:52:20.810 回答