Commit ea51fdd0b93cc174559478b3ea940c9c4c164707

Authored by Angel Caceres
1 parent 5232fab6

ckbtc

@@ -21,10 +21,10 @@ @@ -21,10 +21,10 @@
21 "axios": "^1.6.2", 21 "axios": "^1.6.2",
22 "bcrypt": "^5.1.1", 22 "bcrypt": "^5.1.1",
23 "cors": "^2.8.5", 23 "cors": "^2.8.5",
  24 + "crypto": "^1.0.1",
24 "crypto-js": "^4.2.0", 25 "crypto-js": "^4.2.0",
25 "passport-jwt": "^4.0.1", 26 "passport-jwt": "^4.0.1",
26 "passport-local": "^1.0.0", 27 "passport-local": "^1.0.0",
27 - "prisma": "^5.6.0",  
28 "reflect-metadata": "^0.1.13", 28 "reflect-metadata": "^0.1.13",
29 "rxjs": "^7.8.1" 29 "rxjs": "^7.8.1"
30 }, 30 },
@@ -1986,7 +1986,9 @@ @@ -1986,7 +1986,9 @@
1986 "version": "5.6.0", 1986 "version": "5.6.0",
1987 "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.6.0.tgz", 1987 "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.6.0.tgz",
1988 "integrity": "sha512-Mt2q+GNJpU2vFn6kif24oRSBQv1KOkYaterQsi0k2/lA+dLvhRX6Lm26gon6PYHwUM8/h8KRgXIUMU0PCLB6bw==", 1988 "integrity": "sha512-Mt2q+GNJpU2vFn6kif24oRSBQv1KOkYaterQsi0k2/lA+dLvhRX6Lm26gon6PYHwUM8/h8KRgXIUMU0PCLB6bw==",
1989 - "hasInstallScript": true 1989 + "hasInstallScript": true,
  1990 + "optional": true,
  1991 + "peer": true
1990 }, 1992 },
1991 "node_modules/@prisma/engines-version": { 1993 "node_modules/@prisma/engines-version": {
1992 "version": "5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee", 1994 "version": "5.6.0-32.e95e739751f42d8ca026f6b910f5a2dc5adeaeee",
@@ -3858,6 +3860,12 @@ @@ -3858,6 +3860,12 @@
3858 "node": "*" 3860 "node": "*"
3859 } 3861 }
3860 }, 3862 },
  3863 + "node_modules/crypto": {
  3864 + "version": "1.0.1",
  3865 + "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
  3866 + "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
  3867 + "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in."
  3868 + },
3861 "node_modules/crypto-js": { 3869 "node_modules/crypto-js": {
3862 "version": "4.2.0", 3870 "version": "4.2.0",
3863 "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", 3871 "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
@@ -7644,6 +7652,8 @@ @@ -7644,6 +7652,8 @@
7644 "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.6.0.tgz", 7652 "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.6.0.tgz",
7645 "integrity": "sha512-EEaccku4ZGshdr2cthYHhf7iyvCcXqwJDvnoQRAJg5ge2Tzpv0e2BaMCp+CbbDUwoVTzwgOap9Zp+d4jFa2O9A==", 7653 "integrity": "sha512-EEaccku4ZGshdr2cthYHhf7iyvCcXqwJDvnoQRAJg5ge2Tzpv0e2BaMCp+CbbDUwoVTzwgOap9Zp+d4jFa2O9A==",
7646 "hasInstallScript": true, 7654 "hasInstallScript": true,
  7655 + "optional": true,
  7656 + "peer": true,
7647 "dependencies": { 7657 "dependencies": {
7648 "@prisma/engines": "5.6.0" 7658 "@prisma/engines": "5.6.0"
7649 }, 7659 },
@@ -37,10 +37,10 @@ @@ -37,10 +37,10 @@
37 "axios": "^1.6.2", 37 "axios": "^1.6.2",
38 "bcrypt": "^5.1.1", 38 "bcrypt": "^5.1.1",
39 "cors": "^2.8.5", 39 "cors": "^2.8.5",
  40 + "crypto": "^1.0.1",
40 "crypto-js": "^4.2.0", 41 "crypto-js": "^4.2.0",
41 "passport-jwt": "^4.0.1", 42 "passport-jwt": "^4.0.1",
42 "passport-local": "^1.0.0", 43 "passport-local": "^1.0.0",
43 - "prisma": "^5.6.0",  
44 "reflect-metadata": "^0.1.13", 44 "reflect-metadata": "^0.1.13",
45 "rxjs": "^7.8.1" 45 "rxjs": "^7.8.1"
46 }, 46 },
1 -import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';  
2 -import { PrismaClient } from '@prisma/client';  
3 -  
4 -@Injectable()  
5 -export class PrismaService extends PrismaClient implements OnModuleInit {  
6 - /**  
7 - * The onModuleInit is optional — if you leave it out, Prisma will connect lazily on its first call to the database.  
8 - */  
9 - async onModuleInit() {  
10 - await this.$connect();  
11 - }  
12 -  
13 - async enableShutdownHooks(app: INestApplication) {  
14 - this.$on('beforeExit' as never, async () => {  
15 - await app.close();  
16 - });  
17 - }  
18 -}  
@@ -3,7 +3,7 @@ import { AppModule } from './modules/app/app.module'; @@ -3,7 +3,7 @@ import { AppModule } from './modules/app/app.module';
3 3
4 async function bootstrap() { 4 async function bootstrap() {
5 const app = await NestFactory.create(AppModule); 5 const app = await NestFactory.create(AppModule);
6 - app.enableCors({ origin: String(process.env.ALLOWED_ORIGINS).split(',') }); 6 + // app.enableCors({ origin: String(process.env.ALLOWED_ORIGINS).split(',') });
7 await app.listen(3000); 7 await app.listen(3000);
8 } 8 }
9 bootstrap(); 9 bootstrap();
@@ -2,7 +2,7 @@ import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; @@ -2,7 +2,7 @@ import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
2 import { AppController } from './app.controller'; 2 import { AppController } from './app.controller';
3 import { AppService } from './app.service'; 3 import { AppService } from './app.service';
4 import { UsersModule } from '../users/users.module'; 4 import { UsersModule } from '../users/users.module';
5 -import { PrismaService } from 'src/config/prisma.service'; 5 +import { PrismaService } from 'libs/private-api/config/prisma.service';
6 import { AuthModule } from '../auth/auth.module'; 6 import { AuthModule } from '../auth/auth.module';
7 import { DescryptMiddleware } from './middlewares/decrypt.middleware'; 7 import { DescryptMiddleware } from './middlewares/decrypt.middleware';
8 import { PublicModule } from '@app/public'; 8 import { PublicModule } from '@app/public';
@@ -2,7 +2,7 @@ import { Controller, Request, Post, UseGuards } from '@nestjs/common'; @@ -2,7 +2,7 @@ import { Controller, Request, Post, UseGuards } from '@nestjs/common';
2 import { AuthService } from './auth.service'; 2 import { AuthService } from './auth.service';
3 import { AuthGuard } from '@nestjs/passport'; 3 import { AuthGuard } from '@nestjs/passport';
4 import { clientEncryptBody, privateEncryptBody } from 'src/helpers/encryptor.helper'; 4 import { clientEncryptBody, privateEncryptBody } from 'src/helpers/encryptor.helper';
5 -import { ApiKeyGuard } from './guards/public-api-key.guard'; 5 +import { PublicApiKeyGuard } from './guards/public-api-key.guard';
6 6
7 @Controller('auth') 7 @Controller('auth')
8 export class AuthController { 8 export class AuthController {
@@ -14,7 +14,7 @@ export class AuthController { @@ -14,7 +14,7 @@ export class AuthController {
14 return privateEncryptBody(await this.authService.privateLogin(req.user)); 14 return privateEncryptBody(await this.authService.privateLogin(req.user));
15 } 15 }
16 16
17 - @UseGuards(ApiKeyGuard) 17 + @UseGuards(PublicApiKeyGuard)
18 @Post('public/login') 18 @Post('public/login')
19 async publicLogin(@Request() req) { 19 async publicLogin(@Request() req) {
20 return clientEncryptBody(await this.authService.publicLogin()); 20 return clientEncryptBody(await this.authService.publicLogin());
@@ -7,7 +7,7 @@ import { LocalStrategy } from './strategies/local.strategy'; @@ -7,7 +7,7 @@ import { LocalStrategy } from './strategies/local.strategy';
7 import { JwtStrategy } from './strategies/private-jwt.strategy'; 7 import { JwtStrategy } from './strategies/private-jwt.strategy';
8 import { UsersModule } from '../users/users.module'; 8 import { UsersModule } from '../users/users.module';
9 import { UsersService } from '../users/users.service'; 9 import { UsersService } from '../users/users.service';
10 -import { PrismaService } from 'src/config/prisma.service'; 10 +import { PrismaService } from 'libs/private-api/config/prisma.service';
11 import { AuthController } from './auth.controller'; 11 import { AuthController } from './auth.controller';
12 12
13 @Module({ 13 @Module({
@@ -12,7 +12,7 @@ export class AuthService { @@ -12,7 +12,7 @@ export class AuthService {
12 12
13 async validateUser(email: string, pass: string): Promise<any> { 13 async validateUser(email: string, pass: string): Promise<any> {
14 const user = await this.userService.findByMail(email); 14 const user = await this.userService.findByMail(email);
15 - if (bcrypt.compareSync(pass, user.password)) { 15 + if (bcrypt.compareSync(pass, String(user.userPassword))) {
16 const { ...result } = user; 16 const { ...result } = user;
17 return result; 17 return result;
18 } 18 }
  1 +// token de auth
1 export const jwtConstants = { secret: String(process.env.TOKEN_SECRET) }; 2 export const jwtConstants = { secret: String(process.env.TOKEN_SECRET) };
2 export const jwtExp = String(process.env.TOKEN_EXPIRATION); 3 export const jwtExp = String(process.env.TOKEN_EXPIRATION);
1 import { Module } from '@nestjs/common'; 1 import { Module } from '@nestjs/common';
2 import { UsersService } from './users.service'; 2 import { UsersService } from './users.service';
3 import { UsersController } from './users.controller'; 3 import { UsersController } from './users.controller';
4 -import { PrismaService } from 'src/config/prisma.service'; 4 +import { PrismaService } from 'libs/private-api/config/prisma.service';
5 5
6 @Module({ 6 @Module({
7 imports: [], 7 imports: [],
1 import { Injectable } from '@nestjs/common'; 1 import { Injectable } from '@nestjs/common';
2 -import { PrismaService } from 'src/config/prisma.service'; 2 +import { PrismaService } from 'libs/private-api/config/prisma.service';
3 3
4 @Injectable() 4 @Injectable()
5 export class UsersService { 5 export class UsersService {
@@ -7,19 +7,19 @@ export class UsersService { @@ -7,19 +7,19 @@ export class UsersService {
7 create() { } 7 create() { }
8 8
9 findAll() { 9 findAll() {
10 - return this.prisma.user.findMany({  
11 - select: { id: true, email: true, name: true },  
12 - }); 10 + // return this.prisma.user.findMany({
  11 + // select: { id: true, email: true, name: true },
  12 + // });
13 } 13 }
14 14
15 findOne(id: string) { 15 findOne(id: string) {
16 - return this.prisma.user.findUnique({  
17 - where: { id },  
18 - select: { id: true, email: true, name: true },  
19 - }); 16 + // return this.prisma.user.findUnique({
  17 + // where: { id },
  18 + // select: { id: true, email: true, name: true },
  19 + // });
20 } 20 }
21 21
22 findByMail(email: string) { 22 findByMail(email: string) {
23 - return this.prisma.user.findFirstOrThrow({ where: { email } }); 23 + return this.prisma.brUser.findFirstOrThrow({ where: { userUsername: email } });
24 } 24 }
25 } 25 }
Please register or login to post a comment