diff --git a/client/src/app/pages/crafting/crafting.page.ts b/client/src/app/pages/crafting/crafting.page.ts index abf3671..1d94487 100644 --- a/client/src/app/pages/crafting/crafting.page.ts +++ b/client/src/app/pages/crafting/crafting.page.ts @@ -83,7 +83,6 @@ export class CraftingPage implements OnInit { updateDiscoveries() { this.userService.getDiscoveries().subscribe(({ discoveries }: any) => { this.discoveries = discoveries; - console.log(discoveries); }); } diff --git a/client/src/app/pages/login/login.page.html b/client/src/app/pages/login/login.page.html index b2cf181..48a93a6 100644 --- a/client/src/app/pages/login/login.page.html +++ b/client/src/app/pages/login/login.page.html @@ -37,7 +37,7 @@ - + diff --git a/client/src/app/pages/login/login.page.ts b/client/src/app/pages/login/login.page.ts index 2bad505..f82b650 100644 --- a/client/src/app/pages/login/login.page.ts +++ b/client/src/app/pages/login/login.page.ts @@ -123,7 +123,12 @@ export class LoginPage implements OnInit { this.authService .login(this.loginForm.value.email, this.loginForm.value.password) .subscribe({ - next: () => { + next: (res: any) => { + if (res.error) { + this.loginError = res.error; + return; + } + this.router.navigate(['/']); this.notificationService.getNotifications(); }, @@ -150,7 +155,12 @@ export class LoginPage implements OnInit { this.registerForm.value.username, ) .subscribe({ - next: () => { + next: (res: any) => { + if (res.error) { + this.registerError = res.error; + return; + } + if ( !this.registerForm.value.email || !this.registerForm.value.password @@ -163,7 +173,12 @@ export class LoginPage implements OnInit { this.registerForm.value.password, ) .subscribe({ - next: () => { + next: (res: any) => { + if (res.error) { + this.registerError = res.error; + return; + } + this.router.navigate(['/']); this.notificationService.getNotifications(); }, diff --git a/server/src/modules/auth/auth.controller.ts b/server/src/modules/auth/auth.controller.ts index f362d3a..faf3cc1 100644 --- a/server/src/modules/auth/auth.controller.ts +++ b/server/src/modules/auth/auth.controller.ts @@ -27,17 +27,13 @@ export class AuthController { @Post('register') signUp(@Body() signInDto: Record) { if (!signInDto.username || !signInDto.password || !signInDto.email) - throw new BadRequestException('Missing username, password or email'); + return { error: 'Missing username, password or email' }; if (signInDto.username.length < 2 || signInDto.username.length > 20) - throw new BadRequestException( - 'Username must be between 2 and 20 characters long', - ); + return { error: 'Username must be between 2 and 20 characters long' }; if (signInDto.password.length < 8) - throw new BadRequestException( - 'Password must be at least 8 characters long', - ); + return { error: 'Password must be at least 8 characters long' }; return this.authService.signUp( signInDto.username, diff --git a/server/src/modules/auth/auth.service.ts b/server/src/modules/auth/auth.service.ts index 239775d..6daac5b 100644 --- a/server/src/modules/auth/auth.service.ts +++ b/server/src/modules/auth/auth.service.ts @@ -1,8 +1,4 @@ -import { - BadRequestException, - Injectable, - UnauthorizedException, -} from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import * as bcrypt from 'bcrypt'; import { sample } from 'lodash'; @@ -28,11 +24,9 @@ export class AuthService { username: string, password: string, email: string, - ): Promise { + ): Promise { if (this.contentService.censor.isProfaneIsh(username)) - throw new BadRequestException( - 'Username is somewhat profane. Please choose again.', - ); + return { error: 'Username is somewhat profane. Please choose again.' }; const usersWithUsername = await this.userService.getAllUsersWithUsername( username, @@ -42,7 +36,7 @@ export class AuthService { ); if (usersWithUsername.length > 9998) { - throw new BadRequestException('Username is not available.'); + return { error: `Username ${username} is not available.` }; } else if (usersWithUsername.length >= 1) { const usedDiscriminators = new Set( usersWithUsername.map((user) => user.discriminator), @@ -53,7 +47,7 @@ export class AuthService { } const discriminator = sample(availableDiscriminators); - if (!discriminator) throw new BadRequestException('Failed to create user.'); + if (!discriminator) return { error: 'Failed to create user.' }; const hash = await bcrypt.hash(password, 10); const newUser = new User(username, discriminator, hash, email); @@ -62,12 +56,12 @@ export class AuthService { try { createdUser = await this.userService.createUser(newUser); } catch (err) { - throw new BadRequestException( - 'Failed to create user. This email might already be in use.', - ); + return { + error: 'Failed to create user. This email might already be in use.', + }; } - if (!createdUser) throw new BadRequestException('Failed to create user.'); + if (!createdUser) return { error: 'Failed to create user.' }; this.logger.verbose( `Registered new user: ${createdUser.username}#${createdUser.discriminator}`, @@ -81,15 +75,15 @@ export class AuthService { async signIn( username: string, password: string, - ): Promise { + ): Promise { const user = await this.userService.findUserByEmail(username); if (!user) { - throw new UnauthorizedException(); + return { error: 'Unable to sign in.' }; } const isMatch = await bcrypt.compare(password, user.password); if (!isMatch) { - throw new UnauthorizedException(); + return { error: 'Unable to sign in.' }; } await this.userService.updateUserOnlineTimeById(user._id.toString()); diff --git a/server/src/utils/http-exception.filter.ts b/server/src/utils/http-exception.filter.ts index 760ff04..64aca81 100644 --- a/server/src/utils/http-exception.filter.ts +++ b/server/src/utils/http-exception.filter.ts @@ -11,6 +11,7 @@ import * as Rollbar from 'rollbar'; @Catch(HttpException) export class HttpExceptionFilter implements ExceptionFilter { + private readonly ignoredCodes = [401]; private rollbar: Rollbar; constructor(@Inject(ROLLBAR_CONFIG) private rollbarConfig) { @@ -23,7 +24,7 @@ export class HttpExceptionFilter implements ExceptionFilter { const request = ctx.getRequest(); const status = exception.getStatus(); - if (this.rollbar) { + if (this.rollbar && !this.ignoredCodes.includes(status)) { this.rollbar.error(exception); }