Created signup form
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user