feat: add backend-mock app
This commit is contained in:
49
apps/backend-mock/src/modules/auth/auth.controller.ts
Normal file
49
apps/backend-mock/src/modules/auth/auth.controller.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user