auth.controller.ts
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
}
}