[英]NestJS Axios module - can't resolve dependencies
I'm having a baffling problem with the NestJS Axios module.我对 NestJS Axios 模块有一个莫名其妙的问题。 I have it imported in my module like so:
我将它导入到我的模块中,如下所示:
import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';
import { PassportModule } from '@nestjs/passport';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { AuthStrategy } from './auth.strategy';
@Module({
controllers: [AuthController],
providers: [AuthService],
imports: [HttpModule, PassportModule, AuthStrategy],
})
And I'm attempting to use it in my AuthStrategy
like so:我试图在我的
AuthStrategy
中使用它,如下所示:
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { Strategy } from 'passport-oauth2';
@Injectable()
export class AuthStrategy extends PassportStrategy(Strategy) {
constructor(private readonly httpService: HttpService) {
super({
authorizationURL: `${process.env['OAUTH_DOMAIN']}/authorize`,
tokenURL: `${process.env['OAUTH_DOMAIN']}/oauth/token`,
clientID: process.env['OAUTH_CLIENT_ID'],
clientSecret: process.env['OAUTH_CLIENT_SECRET'],
callbackURL: process.env['OAUTH_REDIRECT_URL'],
scope: ['openid', 'email', 'profile'],
});
}
async validate(accessToken: string): Promise<any> {
const data = await this.httpService.get(`${process.env['OAUTH_DOMAIN']}/`, {
headers: { Authorization: `Bearer ${accessToken}` },
});
console.log(data);
}
}
But I get the error:但我得到了错误:
Error: Nest can't resolve dependencies of the AuthStrategy (?). Please make sure that the argument HttpService at index [0] is available in the AuthStrategy context.
Where am I going wrong?我哪里错了? I've done what the error suggests, but it's still not working
我已经完成了错误提示的操作,但仍然无法正常工作
Somewhere in your application, you have AuthStrategy
(a provider) added to a module's imports
array.在您的应用程序的某处,您将
AuthStrategy
(提供程序)添加到模块的imports
数组中。 Providers should never be in the imports
arrays.提供者永远不应该在
imports
arrays 中。
You can learn more about reading and dissecting the error message from the docs page .您可以从文档页面了解有关阅读和剖析错误消息的更多信息。
There are a few gotchas, that are common.
有一些陷阱,很常见。 One is putting a provider in an
imports
array.一种是将提供者放入
imports
数组中。 If this is the case, the error will have the provider's name where<module>
should be.如果是这种情况,错误将包含提供程序的名称,其中
<module>
应该是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.