diff --git a/dto/index.ts b/dto/index.ts index a33fc9f..f7b0a1d 100644 --- a/dto/index.ts +++ b/dto/index.ts @@ -43,6 +43,7 @@ export interface CreateFolderResponse extends BaseResponse { id: number; } +export type SignupResponse = DeleteResponse; export type UploadFileResponse = DeleteResponse; export interface DeleteResponse extends BaseResponse { statusCode: 200; diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 4fc6d32..312da29 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -16,6 +16,7 @@ import { GetRootResponse, LoginResponse, RefreshResponse, + SignupResponse, UploadFileResponse } from '../../dto'; import jwtDecode, { JwtPayload } from 'jwt-decode'; @@ -94,7 +95,7 @@ export const auth_login = ( export const auth_signup = ( username: string, password: string -): Promise => +): Promise => post('/api/auth/signup', { username: username, password: password diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 1646fa9..30c6a3e 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -1,5 +1,6 @@ import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'; import LoginView from '@/views/LoginView.vue'; +import SignupView from '@/views/SignupView.vue'; import HomeView from '@/views/HomeView.vue'; import AboutView from '@/views/AboutView.vue'; import FSView from '@/views/FSView.vue'; @@ -19,6 +20,11 @@ const routes: Array = [ name: 'login', component: LoginView }, + { + path: '/signup', + name: 'signup', + component: SignupView + }, { path: '/fs/:node_id', name: 'fs', diff --git a/frontend/src/views/LoginView.vue b/frontend/src/views/LoginView.vue index 5bdae57..9e9815e 100644 --- a/frontend/src/views/LoginView.vue +++ b/frontend/src/views/LoginView.vue @@ -13,7 +13,7 @@ const jwt = inject('jwt') as TokenInjectType; async function login() { if (username.value === '' || password.value === '') { - error.value = 'Username and/or Password missing'; + error.value = 'Email and/or Password missing'; return; } const res = await auth_login(username.value, password.value); @@ -38,6 +38,7 @@ async function login() { + Signup instead? diff --git a/frontend/src/views/SignupView.vue b/frontend/src/views/SignupView.vue new file mode 100644 index 0000000..481ff0c --- /dev/null +++ b/frontend/src/views/SignupView.vue @@ -0,0 +1,35 @@ + + + + + diff --git a/src/controller/auth.ts b/src/controller/auth.ts index 253bebb..55131d4 100644 --- a/src/controller/auth.ts +++ b/src/controller/auth.ts @@ -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 { + ): Promise { if ((await this.authService.findUser(username)) != null) throw new BadRequestException('Username already taken'); await this.authService.signup(username, password); diff --git a/src/services/auth.ts b/src/services/auth.ts index 0d192f9..b3811e2 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -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);