Created signup form

This commit is contained in:
2022-08-23 22:15:01 +02:00
parent 6f245534f0
commit 41b1e8837b
7 changed files with 56 additions and 6 deletions

View File

@@ -11,10 +11,10 @@ import { AuthService } from '../services/auth';
import { AuthGuard } from '@nestjs/passport';
import { Public } from '../authguards';
import {
BaseResponse,
ErrorResponse,
LoginResponse,
RefreshResponse
RefreshResponse,
SignupResponse
} from 'dto';
@Controller('api/auth')
@@ -37,7 +37,7 @@ export default class AuthController {
async signup(
@Body('username') username,
@Body('password') password
): Promise<BaseResponse | ErrorResponse> {
): Promise<SignupResponse | ErrorResponse> {
if ((await this.authService.findUser(username)) != null)
throw new BadRequestException('Username already taken');
await this.authService.signup(username, password);

View File

@@ -1,4 +1,8 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import {
BadRequestException,
Injectable,
UnauthorizedException
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { JWTToken, User, UserRole } from '../entities';
import { Repository, LessThanOrEqual } from 'typeorm';
@@ -81,6 +85,8 @@ export class AuthService {
}
async signup(username: string, password: string) {
if (await this.findUser(username))
throw new BadRequestException('User already exists');
const user = new User();
user.name = username;
user.password = await argon2.hash(password);