this is my codes:
Auth Module:
@Module({
imports: [
TypeOrmModule.forFeature([User]),
JwtModule.register({
secret: 'secret',
signOptions: {
expiresIn: '365d',
}
})
],
controllers: [AuthController],
providers: [AuthService],
})
export class AuthModule {}
Auth Controller:
@Controller("api")
export class AuthController {
constructor(private readonly appService: AuthService, private readonly jwtService:JwtService ) {}
}
Auth Service:
@Injectable()
export class AuthService {
constructor(@InjectRepository(User) private userRepo:Repository<User>) {}
}
Auth Guard:
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private readonly jwtService:JwtService,private readonly userService:AuthService) {}
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
return ...
}
}
App Module:
@Module({
imports: [
AuthModule,
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: '',
database: 'nestjs',
entities: [User,Post],
synchronize: true,
}),
TypeOrmModule.forFeature([Post]),
],
controllers: [PostController],
providers: [PostService],
})
export class AppModule{}
And i have this error: Nest can't resolve dependencies of the AuthGuard (?, AuthService). Please make sure that the argument JwtService at index [0] is available in the AppModule context .
i defined jwt service in auth module and i imported auth module in app module, but the error says i should import jwt service in app module, why?
i also checked my imports in app module