Fix duplicated guests
This commit is contained in:
@@ -57,12 +57,8 @@ export class AuthController {
|
||||
@HttpCode(200)
|
||||
@Post('guest')
|
||||
async guest(): Promise<JwtToken> {
|
||||
try {
|
||||
const user = await this.usersService.createGuest();
|
||||
return this.authService.login(user);
|
||||
} catch {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
const user = await this.usersService.createGuest();
|
||||
return this.authService.login(user);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { User, Prisma } from '@prisma/client';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import { randomUUID } from 'crypto';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
@@ -42,7 +43,7 @@ export class UsersService {
|
||||
async createGuest(): Promise<User> {
|
||||
return this.prisma.user.create({
|
||||
data: {
|
||||
username: 'Guest',
|
||||
username: `Guest ${randomUUID()}`,
|
||||
isGuest: true,
|
||||
// Not realyl clean but better than a separate table or breaking the api by adding nulls.
|
||||
email: '',
|
||||
|
||||
Reference in New Issue
Block a user