cursor-init/src/modules/auth/auth.controller.ts
expressgy 541dd50ea3 feat: 用户登录
1. 同意HTTP返回类型,写方法
2. 优化错误拦截,返回正确的错误类型
3. 优化auth中的返回类型
2025-07-06 03:45:31 +08:00

85 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file 认证模块Controller层实现
* @author AI Assistant
* @date 2024-12-19
* @lastEditor AI Assistant
* @lastEditTime 2025-01-07
* @description 认证模块的路由控制器,处理用户注册、邮箱激活、用户登录等请求
*/
import { Elysia } from 'elysia';
import { RegisterSchema, ActivateSchema, LoginSchema } from './auth.schema';
import { RegisterResponses, ActivateResponses, LoginResponses } from './auth.response';
import { authService } from './auth.service';
import { tags } from '@/modules/tags';
/**
* 认证控制器
* @description 处理用户认证相关的HTTP请求
*/
export const authController = new Elysia()
/**
* 用户注册接口
* @route POST /api/auth/register
* @description 用户注册,包含验证码验证、用户名邮箱唯一性检查等
* @param body RegisterRequest 注册请求参数
* @returns RegisterSuccessResponse | RegisterErrorResponse
*/
.post(
'/register',
({ body, set }) => authService.register(body),
{
body: RegisterSchema,
detail: {
summary: '用户注册',
description: '用户注册接口,需要提供用户名、邮箱、密码和验证码',
tags: [tags.auth],
operationId: 'registerUser',
},
response: RegisterResponses,
}
)
/**
* 邮箱激活接口
* @route POST /api/auth/activate
* @description 通过激活Token激活用户邮箱
* @param body ActivateRequest 激活请求参数
* @returns ActivateSuccessResponse | ActivateErrorResponse
*/
.post(
'/activate',
({ body, set }) => authService.activate(body),
{
body: ActivateSchema,
detail: {
summary: '邮箱激活',
description: '通过激活Token激活用户邮箱激活成功后用户状态将变为active',
tags: [tags.auth],
operationId: 'activateUser',
},
response: ActivateResponses,
}
)
/**
* 用户登录接口
* @route POST /api/auth/login
* @description 用户登录支持用户名或邮箱登录返回JWT令牌
* @param body LoginRequest 登录请求参数
* @returns LoginSuccessResponse | LoginErrorResponse
*/
.post(
'/login',
({ body, set }) => authService.login(body),
{
body: LoginSchema,
detail: {
summary: '用户登录',
description: '用户登录接口支持用户名或邮箱登录登录成功返回JWT访问令牌和刷新令牌',
tags: [tags.auth],
operationId: 'loginUser',
},
response: LoginResponses,
}
);