Compare commits
No commits in common. "a102b4a21bb6942faaadcacde929bd461791f8c7" and "10e481669e40f25d9149ff4ca112d4dd8fd3950a" have entirely different histories.
a102b4a21b
...
10e481669e
|
@ -9,7 +9,7 @@ services:
|
|||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||
POSTGRES_DB: ${DB_NAME}
|
||||
ports:
|
||||
- "${DB_PORT}:${DB_PORT}"
|
||||
- "${DB_PORT}:5432"
|
||||
pgadmin:
|
||||
container_name: pgadmin4_container
|
||||
image: dpage/pgadmin4
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"npmName": "Ticket-API-Services",
|
||||
"npmVersion": "0.0.0",
|
||||
"providedIn": "root",
|
||||
"withInterfaces": true,
|
||||
"enumNameSuffix": "Enum",
|
||||
"supportsES6": true,
|
||||
"ngVersion": "17.0.0",
|
||||
"modelSuffix": "Model",
|
||||
"stringEnums": true,
|
||||
"enumPropertyNaming": "PascalCase",
|
||||
"modelPropertyNaming": "original",
|
||||
"fileNaming": "camelCase",
|
||||
"paramNaming": "camelCase"
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
{
|
||||
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
|
||||
"spaces": 2,
|
||||
"generator-cli": {
|
||||
"version": "7.6.0",
|
||||
"generators": {
|
||||
"typescript-angular": {
|
||||
"generatorName": "typescript-angular",
|
||||
"output": "web-api",
|
||||
"inputSpec": "http://localhost:3000/api-json",
|
||||
"additionalProperties": {
|
||||
"npmName": "Ticket-API-Services",
|
||||
"npmVersion": "0.0.0",
|
||||
"ngVersion": "17.0.0",
|
||||
"npmRepository": null,
|
||||
"configurationPrefix": null,
|
||||
"apiModulePrefix" : "TicketApi",
|
||||
"providedIn": "any",
|
||||
"fileNaming": "camelCase",
|
||||
"paramNaming": "camelCase",
|
||||
"enumPropertyNamingReplaceSpecialChar": "false",
|
||||
"enumUnknownDefaultCase": "false",
|
||||
"enumNameSuffix": "ApiEnum",
|
||||
"enumPropertyNaming": "PascalCase",
|
||||
"modelPropertyNaming": "original",
|
||||
"modelSuffix": "ApiModel",
|
||||
"modelFileSuffix": ".api.model",
|
||||
"serviceSuffix": "ApiService",
|
||||
"serviceFileSuffix": ".api.service",
|
||||
"withInterfaces": true,
|
||||
"supportsES6": true,
|
||||
"stringEnums": true,
|
||||
"sortParamsByRequiredFlag": true,
|
||||
"sortModelPropertiesByRequiredFlag": true,
|
||||
"useSingleRequestParameter": false,
|
||||
"taggedUnions": false,
|
||||
"snapshot": false,
|
||||
"prependFormOrBodyParameters": false,
|
||||
"nullSafeAdditionalProps": false,
|
||||
"legacyDiscriminatorBehavior": true,
|
||||
"ensureUniqueParams": true,
|
||||
"disallowAdditionalPropertiesIfNotPresent": true,
|
||||
"allowUnicodeIdentifiers": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,8 +17,7 @@
|
|||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"build:api": "pnpm openapi-generator-cli generate"
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
|
@ -29,7 +28,6 @@
|
|||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/swagger": "^7.3.1",
|
||||
"@nestjs/typeorm": "^10.0.2",
|
||||
"argon2": "^0.40.1",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"install": "^0.13.0",
|
||||
|
|
|
@ -29,9 +29,6 @@ dependencies:
|
|||
'@nestjs/typeorm':
|
||||
specifier: ^10.0.2
|
||||
version: 10.0.2(@nestjs/common@10.3.7)(@nestjs/core@10.3.7)(reflect-metadata@0.2.2)(rxjs@7.8.1)(typeorm@0.3.20)
|
||||
argon2:
|
||||
specifier: ^0.40.1
|
||||
version: 0.40.1
|
||||
class-transformer:
|
||||
specifier: ^0.5.1
|
||||
version: 0.5.1
|
||||
|
@ -1185,6 +1182,7 @@ packages:
|
|||
/@phc/format@1.0.0:
|
||||
resolution: {integrity: sha512-m7X9U6BG2+J+R1lSOdCiITLLrxm+cWlNI3HUFA92oLO77ObGNzaKdh8pMLqdZcshtkKuV84olNNXDfMc4FezBQ==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/@pkgjs/parseargs@0.11.0:
|
||||
resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==}
|
||||
|
@ -1825,6 +1823,7 @@ packages:
|
|||
'@phc/format': 1.0.0
|
||||
node-addon-api: 7.1.0
|
||||
node-gyp-build: 4.8.1
|
||||
dev: true
|
||||
|
||||
/argparse@1.0.10:
|
||||
resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==}
|
||||
|
@ -4231,6 +4230,7 @@ packages:
|
|||
/node-addon-api@7.1.0:
|
||||
resolution: {integrity: sha512-mNcltoe1R8o7STTegSOHdnJNN7s5EUvhoS7ShnTHDyOSd+8H+UdWODq6qSv67PjC8Zc5JRT8+oLAMCr0SIXw7g==}
|
||||
engines: {node: ^16 || ^18 || >= 20}
|
||||
dev: true
|
||||
|
||||
/node-emoji@1.11.0:
|
||||
resolution: {integrity: sha512-wo2DpQkQp7Sjm2A0cq+sN7EHKO6Sl0ctXeBdFZrL9T9+UywORbufTcTZxom8YqpLQt/FqNMUkOpkZrJVYSKD3A==}
|
||||
|
@ -4252,6 +4252,7 @@ packages:
|
|||
/node-gyp-build@4.8.1:
|
||||
resolution: {integrity: sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/node-int64@0.4.0:
|
||||
resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==}
|
||||
|
|
|
@ -24,7 +24,7 @@ import { CorsMiddleware } from './middleware/cors-middleware/cors.middlware';
|
|||
export class AppModule {
|
||||
configure(consumer: MiddlewareConsumer) {
|
||||
consumer
|
||||
// TODO Redirect via Reverse Proxy all HTTP requests to HTTPS
|
||||
// TODO: Redirect via Reverse Proxy all HTTP requests to HTTPS
|
||||
.apply(
|
||||
CspMiddleware,
|
||||
SecurityHeadersMiddleware,
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export * from './user-credentials.entity';
|
|
@ -4,11 +4,7 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|||
import { ValidationPipe } from '@nestjs/common';
|
||||
|
||||
async function setupSwagger(app) {
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('Tickets API')
|
||||
.setDescription('Description of the API')
|
||||
.setVersion('0.0.0')
|
||||
.build();
|
||||
const config = new DocumentBuilder().build();
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
SwaggerModule.setup('api', app, document);
|
||||
}
|
||||
|
|
|
@ -7,56 +7,39 @@ import {
|
|||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { TokensDto, UserCredentialsDto } from '../models/dto';
|
||||
import { UserCredentialsDto } from '../models/dto';
|
||||
import { Tokens } from '../models/types';
|
||||
import { RefreshTokenGuard } from '../common/guards';
|
||||
import { GetCurrentUser, GetCurrentUserId, Public } from '../common/decorators';
|
||||
import { ApiCreatedResponse, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Authentication')
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
@ApiCreatedResponse({
|
||||
description: 'User signed up successfully',
|
||||
type: TokensDto,
|
||||
})
|
||||
@Public()
|
||||
@Post('signup')
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
public async signup(
|
||||
@Body() userCredentials: UserCredentialsDto
|
||||
): Promise<TokensDto> {
|
||||
): Promise<Tokens> {
|
||||
return this.authService.signup(userCredentials);
|
||||
}
|
||||
|
||||
@ApiCreatedResponse({
|
||||
description: 'User signin successfully',
|
||||
type: TokensDto,
|
||||
})
|
||||
@Public()
|
||||
@Post('signin')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async signin(
|
||||
@Body() userCredentials: UserCredentialsDto
|
||||
): Promise<TokensDto> {
|
||||
): Promise<Tokens> {
|
||||
return this.authService.signin(userCredentials);
|
||||
}
|
||||
|
||||
@ApiCreatedResponse({
|
||||
description: 'User signed out successfully',
|
||||
type: Boolean,
|
||||
})
|
||||
@Post('logout')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async logout(@GetCurrentUserId() userId: number): Promise<boolean> {
|
||||
return this.authService.logout(userId);
|
||||
}
|
||||
|
||||
@ApiCreatedResponse({
|
||||
description: 'User tokens refreshed successfully',
|
||||
type: TokensDto,
|
||||
})
|
||||
@Public()
|
||||
@UseGuards(RefreshTokenGuard)
|
||||
@Post('refresh')
|
||||
|
@ -64,7 +47,7 @@ export class AuthController {
|
|||
public async refresh(
|
||||
@GetCurrentUserId() userId: number,
|
||||
@GetCurrentUser('refresh_token') refresh_token: string
|
||||
): Promise<TokensDto> {
|
||||
): Promise<Tokens> {
|
||||
return this.authService.refresh(userId, refresh_token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
export * from './user-credentials.dto';
|
||||
export * from './tokens.dto';
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class TokensDto {
|
||||
@ApiProperty({
|
||||
title: 'Access token',
|
||||
description: 'Access token',
|
||||
example: 'eyJhbGci',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
public access_token: string;
|
||||
|
||||
@ApiProperty({
|
||||
title: 'Refresh token',
|
||||
description: 'Refresh token',
|
||||
example: 'eyJhbGci',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
public refresh_token: string;
|
||||
}
|
|
@ -1,22 +1,10 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsEmail, IsNotEmpty, IsString, MinLength } from 'class-validator';
|
||||
|
||||
export class UserCredentialsDto {
|
||||
@ApiProperty({
|
||||
title: 'E-Mail',
|
||||
description: 'User email',
|
||||
example: 'foo@bar.com',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsEmail()
|
||||
public email: string;
|
||||
|
||||
@ApiProperty({
|
||||
title: 'Password',
|
||||
description: 'User password',
|
||||
example: '$tr0ngP@$$w0rd',
|
||||
minLength: 8,
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@MinLength(8)
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
export * from './tokens.type';
|
||||
export * from './jwt-payload.type';
|
||||
export * from './jwt-payload-with-refresh-token.type';
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export type Tokens = {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
import { ForbiddenException, Injectable } from '@nestjs/common';
|
||||
import { TokensDto, UserCredentialsDto } from '../models/dto';
|
||||
import { UserCredentialsDto } from '../models/dto';
|
||||
import { Tokens } from '../models/types';
|
||||
import { EncryptionService } from './encryption.service';
|
||||
import { UserRepository } from '../repositories/user.repository';
|
||||
import { TokenManagementService } from './token-management.service';
|
||||
|
@ -12,7 +13,7 @@ export class AuthService {
|
|||
private readonly encryptionService: EncryptionService
|
||||
) {}
|
||||
|
||||
public async signup(userCredentials: UserCredentialsDto): Promise<TokensDto> {
|
||||
public async signup(userCredentials: UserCredentialsDto): Promise<Tokens> {
|
||||
const passwordHashed = await this.encryptionService.hashData(
|
||||
userCredentials.password
|
||||
);
|
||||
|
@ -23,7 +24,7 @@ export class AuthService {
|
|||
return this.generateAndPersistTokens(user.id, user.email);
|
||||
}
|
||||
|
||||
public async signin(userCredentials: UserCredentialsDto): Promise<TokensDto> {
|
||||
public async signin(userCredentials: UserCredentialsDto): Promise<Tokens> {
|
||||
const user = await this.userRepository.findUserByEmail(
|
||||
userCredentials.email
|
||||
);
|
||||
|
@ -42,10 +43,7 @@ export class AuthService {
|
|||
return this.generateAndPersistTokens(user.id, user.email);
|
||||
}
|
||||
|
||||
public async refresh(
|
||||
userId: number,
|
||||
refreshToken: string
|
||||
): Promise<TokensDto> {
|
||||
public async refresh(userId: number, refreshToken: string): Promise<Tokens> {
|
||||
const user = await this.userRepository.findUserById(userId);
|
||||
if (!user || !user.hashedRt) {
|
||||
throw new ForbiddenException('Access Denied');
|
||||
|
@ -73,7 +71,7 @@ export class AuthService {
|
|||
private async generateAndPersistTokens(
|
||||
userId: number,
|
||||
email: string
|
||||
): Promise<TokensDto> {
|
||||
): Promise<Tokens> {
|
||||
const tokens = await this.tokenManagementService.generateTokens(
|
||||
userId,
|
||||
email
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Tokens } from '../models/types';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { TokensDto } from '../models/dto';
|
||||
|
||||
@Injectable()
|
||||
export class TokenManagementService {
|
||||
|
@ -24,10 +24,7 @@ export class TokenManagementService {
|
|||
this.JWT_SECRET_RT = this.configService.get<string>('JWT_SECRET_RT');
|
||||
}
|
||||
|
||||
public async generateTokens(
|
||||
userId: number,
|
||||
email: string
|
||||
): Promise<TokensDto> {
|
||||
public async generateTokens(userId: number, email: string): Promise<Tokens> {
|
||||
const access_token: string = await this.createAccessToken(userId, email);
|
||||
const refresh_token: string = await this.createRefreshToken(userId, email);
|
||||
return { access_token, refresh_token };
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
import { UserCredentials } from 'src/entities';
|
||||
import { UserCredentials } from '../../entities/user-credentials.entity';
|
||||
|
||||
export const databaseConfigFactory = (
|
||||
configService: ConfigService
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
"@types/dompurify": "^3.0.5",
|
||||
"crypto-js": "^4.2.0",
|
||||
"dompurify": "^3.1.3",
|
||||
"primeicons": "^7.0.0",
|
||||
"primeng": "^17.11.0",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0",
|
||||
|
|
|
@ -38,9 +38,6 @@ dependencies:
|
|||
dompurify:
|
||||
specifier: ^3.1.3
|
||||
version: 3.1.3
|
||||
primeicons:
|
||||
specifier: ^7.0.0
|
||||
version: 7.0.0
|
||||
primeng:
|
||||
specifier: ^17.11.0
|
||||
version: 17.11.0(@angular/common@17.3.0)(@angular/core@17.3.0)(@angular/forms@17.3.0)(rxjs@7.8.1)(zone.js@0.14.4)
|
||||
|
@ -8567,10 +8564,6 @@ packages:
|
|||
react-is: 18.2.0
|
||||
dev: true
|
||||
|
||||
/primeicons@7.0.0:
|
||||
resolution: {integrity: sha512-jK3Et9UzwzTsd6tzl2RmwrVY/b8raJ3QZLzoDACj+oTJ0oX7L9Hy+XnVwgo4QVKlKpnP/Ur13SXV/pVh4LzaDw==}
|
||||
dev: false
|
||||
|
||||
/primeng@17.11.0(@angular/common@17.3.0)(@angular/core@17.3.0)(@angular/forms@17.3.0)(rxjs@7.8.1)(zone.js@0.14.4):
|
||||
resolution: {integrity: sha512-EtkXnE7I6gcrqjNDvUi4qvwTvwL/m3hwPJImoO/s088HDOBerwjN1c2Pq3bwGRG8Eg4Ga9nXdE/IrYj2mbAZLw==}
|
||||
peerDependencies:
|
||||
|
|
Loading…
Reference in New Issue