Error received from user registration endpoint
vicehope opened this issue · 2 comments
Steps to reproduce:
- Spin up the service in docker-compose
- Send HTTP POST request to
http://localhost:3000/auth/register
with a request body to register a new user
Result:
Received the following error in the application console:
Error: No data sources defined in your app ... please call addTransactionalDataSources() before application start.
2023-03-22T12:00:30.239177100Z at UserService.createUser (/usr/app/node_modules/typeorm-transactional/src/transactions/wrap-in-transaction.ts:45:13)
2023-03-22T12:00:30.239214200Z at AuthController.userRegister (/usr/app/src/modules/auth/auth.controller.ts:59:48)
2023-03-22T12:00:30.239253100Z at /usr/app/node_modules/@nestjs/core/router/router-execution-context.js:38:29
2023-03-22T12:00:30.239288500Z at processTicksAndRejections (node:internal/process/task_queues:95:5)
Potential fix:
Modify src/app.module.ts
and add the missing dataSourceFactory
callback in the snippet below
TypeOrmModule.forRootAsync({
imports: [SharedModule],
useFactory: (configService: ApiConfigService) =>
configService.postgresConfig,
inject: [ApiConfigService],
dataSourceFactory: async (options) => {
if (!options) {
throw new Error('Invalid options passed');
}
return addTransactionalDataSource(new DataSource(options));
}
})
@vicehope Thanks, It works for me.
Thanks, It works for me.