skunight/nestjs-redis

how to use in guard

Closed this issue · 1 comments

hi
thank you

but i have a problem

in service ,it is ok

but how to use it in guard

import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Observable } from 'rxjs';
import { ApiException } from '../filters/api.exception';
import { ApiCode } from '../enums/api-code.enums';
import { RedisService } from 'nestjs-redis';

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(private readonly redisService: RedisService) {}
  canActivate(
    context: ExecutionContext,
  ): boolean | Promise<boolean> | Observable<boolean> {
    const ctx = context.switchToHttp();
    const request = ctx.getRequest();
    const url = request.originalUrl;
    if (url === '/user-info2') {
      return true;
    } else {
      //  redis中检查token
      throw new ApiException('非法登录状态', ApiCode.TOKEN_ERROR, 200);
    }
  }
}

problem:
An argument for 'redisService' was not provided

how can i use it?

thank you~

use APP_GUARD