mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-25 02:05:11 +02:00
refactor: User and session management
This commit is contained in:
@@ -7,13 +7,15 @@ import {
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { SignInDto } from '../user/user.dto';
|
||||
import { SignInDto, UserDto } from '../user/user.dto';
|
||||
import { ApiOkResponse, ApiProperty } from '@nestjs/swagger';
|
||||
import { ApiException } from '@nanogiants/nestjs-swagger-api-exception-decorator';
|
||||
|
||||
export class SignInResponse {
|
||||
@ApiProperty()
|
||||
accessToken: string;
|
||||
@ApiProperty()
|
||||
user: UserDto;
|
||||
}
|
||||
|
||||
@Controller('auth')
|
||||
@@ -24,12 +26,14 @@ export class AuthController {
|
||||
@ApiOkResponse({ description: 'User found', type: SignInResponse })
|
||||
@ApiException(() => UnauthorizedException)
|
||||
async signIn(@Body() signInDto: SignInDto) {
|
||||
const { token } = await this.authService.signIn(
|
||||
const { token, user } = await this.authService.signIn(
|
||||
signInDto.name,
|
||||
signInDto.password,
|
||||
);
|
||||
|
||||
return {
|
||||
accessToken: token,
|
||||
user: UserDto.fromEntity(user),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export class AuthService {
|
||||
password: string,
|
||||
): Promise<{
|
||||
token: string;
|
||||
user: User;
|
||||
}> {
|
||||
let user = await this.userService.findOneByName(name);
|
||||
if (!user && (await this.userService.noPreviousAdmins()))
|
||||
@@ -34,6 +35,7 @@ export class AuthService {
|
||||
|
||||
return {
|
||||
token: await this.jwtService.signAsync(payload),
|
||||
user,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user