如何实施 Azure-Ad Passport 身份验证?找不到任何相关文档,并在网上阅读发现存在问题。
我正在尝试创建一个数据库模块,如下所示:
const dbProvider = {
provide: 'DB',
useFactory: async (configService:ConfigService) => {
const dbUrl = configService.get<string>('DB_URL')
return Knex({
client: 'pg',
connection: dbUrl
})
},
inject: [ConfigService]
}
@Module({
providers: [ConfigService, dbProvider],
exports: [dbProvider],
})
export class DbModule {}
Run Code Online (Sandbox Code Playgroud)
这是 AppModule 定义:
@Module({
controllers: [AppController],
providers: [Logger, AppService, {
provide: ConfigService,
useFactory: getConfigFactory(['DB_URL']),
}],
exports: [ConfigService]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
和:
export function getConfigFactory(paramsToLoad: string[]) {
return async () => {await getConfigService(paramsToLoad)}
}
export async function getConfigService(paramsToLoad: string[]) {
const …Run Code Online (Sandbox Code Playgroud) 我在网上研究了这个主题,并发现了与此几乎相似的问题 - 但是,我需要知道为什么在 NestJS 中我们必须使用两个包来实现 WebSocket 通信。
这两个包是,
我知道 WebSocket 是一种协议,而 Socket.IO 是一个库,它有服务器版本和客户端版本。
在NestJS的网关文件中实现WebSocket连接时,必须编写类似以下的代码。
import {
ConnectedSocket,
MessageBody,
OnGatewayConnection,
OnGatewayDisconnect,
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
} from '@nestjs/websockets';
import { Server } from 'socket.io';
Run Code Online (Sandbox Code Playgroud)
我的问题,
WebSocketServer和这里有什么区别Server?
为什么我们从 导入而不是Server从导入?socket.io@nestjs/platform-socket.io
您如何用一句话描述使用每个包的目的?
Hi awesome developers,
I'm trying to implement Authentication using passport-local and Nestjs with reference to https://progressivecoder.com/how-to-implement-nestjs-passport-authentication-using-local-strategy/.
I have implemented exactly same but Nestjs always returns 401 Unauthorized even with valid user. I can't seem to find what I am missing.
Code Structure
Authentication Module
User Module
Here's the code:
Authentication Module:
authentication.module.ts
import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { UserModule } from 'src/user/user.module';
import { AuthenticationController } from './controllers/authentication.controller';
import { AuthenticationService …Run Code Online (Sandbox Code Playgroud) 我喜欢 CLI 插件如何让我不必在所有内容上编写 @ApiProperty()。
然而,在我的一些实体中,虽然我希望大多数属性是 @ApiProperty(),但我希望有些属性不是。
我在文档中找不到任何允许我从自动接收 @ApiProperty() 中排除特定字段的内容。
有人知道怎么做吗?
我是事件发射器的新手,并尝试在我的 Nest JS 项目中实现它们,问题是同一个事件被触发多次(准确地说是 6 次),有什么原因以及如何解决这个问题吗?
这是service.ts文件中用于发出事件的
代码片段。this.eventEmitter.emit('company.created', companyCreatedHistory);
这是我的 Event ,位于listener.ts文件中
@Injectable()
export class EntityCreatedListener {
constructor(private readonly historyService: HistoriesService) {}
@OnEvent('company.created')
handleCompanyCreatedEvent(eventObject: typeof eventEmitterObject) {
console.log('Hi')
this.createAuditLog(eventObject, 'company.created');
}
Run Code Online (Sandbox Code Playgroud)
引用自: https: //github.com/nestjs/nest/tree/master/sample/30-event-emitter https://www.npmjs.com/package/@nestjs/event-emitter
我的本地 mongodb 实例出现连接问题。并不是说它不起作用,而是有些东西不起作用,而我期望它们能起作用。
就我而言,我正在尝试使用 mongo 设置我的 NestJS 应用程序(本教程)。它在某个时候指出:
MongooseModule.forRoot('mongodb://localhost/blog')
Run Code Online (Sandbox Code Playgroud)
就我而言,这将是
MongooseModule.forRoot('mongodb://admin:admin@0.0.0.0:27017/blog')
Run Code Online (Sandbox Code Playgroud)
现在,无论我做什么,只要我在该字符串中包含数据库名称,它就不会连接。
mongosh我也可以重现这个问题
$> mongosh mongodb://admin:admin@0.0.0.0:27017/blog
Current Mongosh Log ID: 640c5eeaaf2a65c11a7dda25
Connecting to: mongodb://<credentials>@0.0.0.0:27017/blog? directConnection=true&appName=mongosh+1.8.0
MongoServerError: Authentication failed.
Run Code Online (Sandbox Code Playgroud)
但是当我删除数据库名称时,它可以工作(也在我的 NestJs 应用程序中)。我对 Mongo 不太熟悉,所以也许我完全没有抓住要点,但我认为这应该可行,并且您必须先连接到数据库,然后才能执行任何操作。所以我的问题是,我在这里做错了什么?任何帮助将不胜感激!
nestjs ×7
passport.js ×2
asynchronous ×1
azure ×1
config ×1
eventemitter ×1
mongo-shell ×1
mongodb ×1
socket.io ×1
swagger ×1
websocket ×1