Ola bom dia, esta ocorrendo um erro com a conexao com o postgress, ele log que não reconhece a senha root.
Ja fiz e refiz os passos todos, e ainda sim não roda
Segue os arquivos, o container do docker e o erro que ocorre.
.env
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=root
DB_PASSWORD=root
DB_NAME=loja
DB_ADMIN_EMAIL=admin@root.com
Postgres.config.service.ts
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
@Injectable()
export class PostgresConfigService implements TypeOrmOptionsFactory {
constructor(private configService: ConfigService) {}
createTypeOrmOptions(): TypeOrmModuleOptions {
return {
type: 'postgres',
host: this.configService.get<string>('DB_HOST'),
port: this.configService.get<number>('DB_PORT'),
username: this.configService.get<string>('DB_USERNAME'),
password: this.configService.get<string>('DB_PASSWORD'),
database: this.configService.get<string>('DB_NAME'),
entities: [],
synchronize: true,
};
}
}
app.module.ts
import { Module } from '@nestjs/common';
import { UsersModule } from './users/users.module';
import { ProductModule } from './products/products.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PostgresConfigService } from './config/postgress.config.service';
import { ConfigModule } from '@nestjs/config';
@Module({
imports: [
UsersModule,
ProductModule,
ConfigModule.forRoot({ isGlobal: true }),
TypeOrmModule.forRootAsync({
useClass: PostgresConfigService,
inject: [PostgresConfigService],
}),
],
})
export class AppModule {}
docker-compose.yaml
services:
postgres:
image: postgres:latest
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- postgres
restart: unless-stopped
pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${DB_ADMIN_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${DB_PASSWORD}
ports:
- "8081:80"
depends_on:
- postgres
networks:
- postgres
networks:
postgres:
driver: bridge
volumes:
postgres:
obs: Retirei a versao por conta dela estar obsoleta e não ser mais necessario.
Erro:
error: autentica��o do tipo senha falhou para o usu�rio "root"
at Parser.parseErrorMessage (C:\Users\Usuario\Desktop\API_RESTFUL\api_rest\node_modules\pg-protocol\src\parser.ts:369:69)
at Parser.handlePacket (C:\Users\Usuario\Desktop\API_RESTFUL\api_rest\node_modules\pg-protocol\src\parser.ts:188:21)
at Parser.parse (C:\Users\Usuario\Desktop\API_RESTFUL\api_rest\node_modules\pg-protocol\src\parser.ts:103:30)
at Socket.<anonymous> (C:\Users\Usuario\Desktop\API_RESTFUL\api_rest\node_modules\pg-protocol\src\index.ts:7:48)
at Socket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Socket.Readable.push (node:internal/streams/readable:390:5)
at TCP.onStreamRead (node:internal/stream_base_commons:191:23)