40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
|
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||
|
|
import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
|
||
|
|
import { AuthService } from './auth.service';
|
||
|
|
|
||
|
|
class AppleLoginDto {
|
||
|
|
identityToken: string;
|
||
|
|
authorizationCode: string;
|
||
|
|
user?: { name?: { firstName?: string; lastName?: string }; email?: string };
|
||
|
|
}
|
||
|
|
|
||
|
|
@ApiTags('auth')
|
||
|
|
@Controller('auth')
|
||
|
|
export class AuthController {
|
||
|
|
constructor(private readonly authService: AuthService) {}
|
||
|
|
|
||
|
|
@Post('apple')
|
||
|
|
@HttpCode(HttpStatus.OK)
|
||
|
|
@ApiOperation({ summary: 'Apple 登录', description: '使用 Sign in with Apple 登录,返回访问令牌' })
|
||
|
|
@ApiResponse({ status: 200, description: '登录成功' })
|
||
|
|
async appleLogin(@Body() body: AppleLoginDto) {
|
||
|
|
return this.authService.appleLogin(body);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('refresh')
|
||
|
|
@HttpCode(HttpStatus.OK)
|
||
|
|
@ApiOperation({ summary: '刷新令牌', description: '使用刷新令牌获取新的访问令牌' })
|
||
|
|
@ApiResponse({ status: 200, description: '令牌刷新成功' })
|
||
|
|
async refresh(@Body('refreshToken') refreshToken: string) {
|
||
|
|
return this.authService.refresh(refreshToken);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('logout')
|
||
|
|
@HttpCode(HttpStatus.OK)
|
||
|
|
@ApiOperation({ summary: '用户退出', description: '使当前会话失效' })
|
||
|
|
@ApiResponse({ status: 200, description: '退出成功' })
|
||
|
|
async logout() {
|
||
|
|
return this.authService.logout();
|
||
|
|
}
|
||
|
|
}
|