feat: add backend-mock app

This commit is contained in:
vben
2024-06-30 14:09:44 +08:00
parent c58aa26dbf
commit ca1cad0cd3
71 changed files with 3420 additions and 735 deletions

View File

@@ -0,0 +1,49 @@
import type { RefreshTokenDto } from '@/models/dto/auth.dto';
import { Public } from '@/core/decorator';
import { LocalAuthGuard } from '@/core/guard';
import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Post,
Request,
UseGuards,
} from '@nestjs/common';
import { AuthService } from './auth.service';
@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
/**
* 获取用户信息
* @param req
*/
@Get('getUserInfo')
@HttpCode(HttpStatus.OK)
async getProfile(@Request() req: Request) {
return await this.authService.getUserInfo(req.user.username);
}
/**
* 用户登录
* @param req
*/
@Public()
@UseGuards(LocalAuthGuard)
@Post('login')
@HttpCode(HttpStatus.OK)
async login(@Request() req: Request) {
return await this.authService.login(req.user);
}
@Post('refreshToken')
@HttpCode(HttpStatus.OK)
async refreshToken(@Body() refreshTokenDto: RefreshTokenDto) {
return this.authService.refresh(refreshTokenDto.refreshToken);
}
}