auth a medias

This commit is contained in:
xXpuma99Xx
2022-04-21 16:31:26 -05:00
parent c52e5b7850
commit ede4bbd0dc
9 changed files with 411 additions and 10 deletions
+8 -6
View File
@@ -45,20 +45,21 @@ import { TipoCarrito } from './institucion-tipo-carrito/entity/tipo-carrito.enti
import { TipoEntrada } from './tipo-entrada/entity/tipo-entrada.entity';
import { TipoUsuario } from './tipo-usuario/entity/tipo-usuario.entity';
import { Usuario } from './usuario/entity/usuario.entity';
import { AuthModule } from './auth/auth.module';
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => {
useFactory: (configService: ConfigService) => {
return {
type: 'mariadb',
host: config.get<string>('DB_HOST'),
database: config.get<string>('DB'),
username: config.get<string>('DB_USER'),
password: config.get<string>('DB_PASSWORD'),
port: config.get<number>('DB_PORT'),
host: configService.get<string>('DB_HOST'),
database: configService.get<string>('DB'),
username: configService.get<string>('DB_USER'),
password: configService.get<string>('DB_PASSWORD'),
port: configService.get<number>('DB_PORT'),
synchronize: true,
entities: [
Carrera,
@@ -88,6 +89,7 @@ import { Usuario } from './usuario/entity/usuario.entity';
};
},
}),
AuthModule,
CarreraModule,
CarreraProgramaModule,
CarritoModule,
+18
View File
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
describe('AuthController', () => {
let controller: AuthController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
}).compile();
controller = module.get<AuthController>(AuthController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
+4
View File
@@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';
@Controller('auth')
export class AuthController {}
+25
View File
@@ -0,0 +1,25 @@
import { ConfigService } from '@nestjs/config';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { JwtStrategyService } from './strategy/jwt-strategy.service';
@Module({
imports: [
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.registerAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => {
return {
secret: configService.get<string>('AUTH_SECRETKEY'),
signOptions: { expiresIn: '30s' },
};
},
}),
],
controllers: [AuthController],
providers: [AuthService, JwtStrategyService],
})
export class AuthModule {}
+18
View File
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
describe('AuthService', () => {
let service: AuthService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
}).compile();
service = module.get<AuthService>(AuthService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
+9
View File
@@ -0,0 +1,9 @@
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
@Injectable()
export class AuthService {
constructor() {}
validate() {}
}
+14
View File
@@ -0,0 +1,14 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy, ExtractJwt } from 'passport-jwt';
@Injectable()
export class JwtStrategyService extends PassportStrategy(Strategy) {
constructor(private configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: configService.get<string>('AUTH_SECRETKEY'),
});
}
}