// apps/box-app-api/src/feature/auth/auth.controller.ts import { Body, Controller, Post, Req } from '@nestjs/common'; import { AuthService } from './auth.service'; import { Request } from 'express'; import { LoginDto } from './login.dto'; import { ApiTags, ApiOperation, ApiResponse, ApiOkResponse, } from '@nestjs/swagger'; @ApiTags('授权') @Controller('auth') export class AuthController { constructor(private readonly authService: AuthService) {} @Post('login') @ApiOperation({ summary: '用户登录/落地注册', description: '首次登录会自动注册并绑定渠道', }) @ApiOkResponse({ description: '登录成功,返回 uid、绑定后的 channelId,并在可用时返回启动广告 startupAds。', }) @ApiResponse({ status: 400, description: '请求参数错误' }) async login(@Body() body: LoginDto, @Req() req: Request) { const ip = (req.headers['x-forwarded-for'] as string)?.split(',')[0]?.trim() || (req.headers['x-real-ip'] as string) || req.ip; const userAgent = req.headers['user-agent']; return this.authService.login({ uid: body.uid, ip, userAgent, appVersion: body.appVersion, os: body.os, channelId: body.channelId, machine: body.machine, }); } }