瀏覽代碼

feat: save

gemercheung 6 月之前
父節點
當前提交
014407ec6f
共有 1 個文件被更改,包括 8 次插入3 次删除
  1. 8 3
      packages/backend/src/modules/auth/auth.controller.ts

+ 8 - 3
packages/backend/src/modules/auth/auth.controller.ts

@@ -1,4 +1,4 @@
-import { Body, Controller, Get, Param, Post, Req, Res, UseGuards } from '@nestjs/common';
+import { Body, Controller, Get, Param, Post, Req, Res, UseGuards, Session } from '@nestjs/common';
 import { AuthService } from './auth.service';
 import { JwtGuard, LocalGuard, PreviewGuard } from '@/common/guards';
 import { ChangePasswordDto, RegisterUserDto, LoginUserDto } from './dto';
@@ -18,13 +18,18 @@ export class AuthController {
 
   @UseGuards(LocalGuard)
   @Post('login')
-  async login(@Req() req: any, @Body() body: LoginUserDto) {
+  async login(
+    @Session() session: Record<string, any>,
+    @Req() req: any,
+    @Body() body: LoginUserDto,
+  ) {
     // 预览环境下可快速登录,不用验证码
     if (this.configService.get('IS_PREVIEW') === 'true' && body.isQuick) {
       return this.authService.login(req.user, req.session?.code);
     }
     // 判断验证码是否正确
-    if (req.session?.code?.toLocaleLowerCase() !== body.captcha?.toLocaleLowerCase()) {
+    console.log('session', session);
+    if (session.code?.toLocaleLowerCase() !== body.captcha?.toLocaleLowerCase()) {
       throw new CustomException(ErrorCode.ERR_10003);
     }