feat: Creating the first user

This commit is contained in:
Aleksi Lassila
2024-06-02 02:59:38 +03:00
parent 052ea44548
commit db21aef3f3
12 changed files with 141 additions and 44 deletions

View File

@@ -1,6 +1,7 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { UserService } from '../user/user.service';
import { JwtService } from '@nestjs/jwt';
import { User } from '../user/user.entity';
export interface AccessTokenPayload {
sub: string;
@@ -19,7 +20,9 @@ export class AuthService {
): Promise<{
token: string;
}> {
const user = await this.userService.findOneByName(name);
let user = await this.userService.findOneByName(name);
if (!user && (await this.userService.noPreviousAdmins()))
user = await this.userService.create(name, password, true);
if (!(user && user.password === password)) {
throw new UnauthorizedException();