Spaces:
Runtime error
Runtime error
| import { Controller, Post, Body, Req, UseGuards } from '@nestjs/common'; | |
| import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; | |
| import { UserAuthService } from './auth.service'; | |
| import { UserRegisterDto } from './dto/register.dto'; | |
| import { UserLoginDto } from './dto/login.dto'; | |
| import { VerifyEmailOtpDto } from './dto/verify-email-otp.dto'; | |
| import { ResendEmailOtpDto } from './dto/resend-email-otp.dto'; | |
| import { RegisterPhoneDto } from './dto/register-phone.dto'; | |
| import { VerifyPhoneOtpDto } from './dto/verify-phone-otp.dto'; | |
| import { CompleteProfileDto } from './dto/complete-profile.dto'; | |
| import { UserRefreshTokenDto } from './dto/refresh-token.dto'; | |
| import { Public } from 'src/shared/decorators/public.decorator'; | |
| import { GetUser } from 'src/shared/decorators/get-user.decorator'; | |
| import { LogToDiscord } from 'src/shared/decorators/log-to-discord.decorator'; | |
| import type { UserSessionType } from 'src/shared/types/user-session.type'; | |
| import { UserAuthGuard } from './guards/user-auth.guard'; | |
| ('User: Authentication') | |
| ('user/auth') | |
| (UserAuthGuard) | |
| () | |
| export class UserAuthController { | |
| constructor(private readonly userAuthService: UserAuthService) {} | |
| // PHASE 1: Initial Registration | |
| () | |
| ('register') | |
| ({ summary: 'Register a new user (Step 1/5)' }) | |
| async register(() registerDto: UserRegisterDto) { | |
| return this.userAuthService.register(registerDto); | |
| } | |
| // PHASE 2: Email Verification | |
| () | |
| ('verify-email') | |
| ({ summary: 'Verify email with OTP (Step 2/5)' }) | |
| async verifyEmail(() verifyDto: VerifyEmailOtpDto) { | |
| return this.userAuthService.verifyEmailOtp(verifyDto); | |
| } | |
| () | |
| ('resend-email-otp') | |
| ({ summary: 'Resend email OTP' }) | |
| async resendEmailOtp(() resendDto: ResendEmailOtpDto) { | |
| return this.userAuthService.resendEmailOtp(resendDto); | |
| } | |
| // PHASE 3: Phone Registration | |
| () | |
| ('register-phone') | |
| ({ summary: 'Register phone number (Step 3/5)' }) | |
| async registerPhone(() registerPhoneDto: RegisterPhoneDto) { | |
| return this.userAuthService.registerPhone(registerPhoneDto); | |
| } | |
| // PHASE 4: Phone Verification | |
| () | |
| ('verify-phone') | |
| ({ summary: 'Verify phone with OTP (Step 4/5)' }) | |
| async verifyPhone(() verifyDto: VerifyPhoneOtpDto) { | |
| return this.userAuthService.verifyPhoneOtp(verifyDto); | |
| } | |
| // PHASE 5: Complete Profile | |
| () | |
| ('complete-profile') | |
| ({ summary: 'Complete profile and activate account (Step 5/5)' }) | |
| async completeProfile( | |
| () completeDto: CompleteProfileDto, | |
| () request: any, | |
| ) { | |
| return this.userAuthService.completeProfile(completeDto, request); | |
| } | |
| // Login (Only for verified users) | |
| () | |
| ('login') | |
| ({ summary: 'Login user (Only verified accounts)' }) | |
| async login(() loginDto: UserLoginDto, () request: any) { | |
| return this.userAuthService.login(loginDto, request); | |
| } | |
| () | |
| ('logout') | |
| ({ summary: 'Logout user' }) | |
| async logout(() sessionData: UserSessionType) { | |
| return this.userAuthService.logout(sessionData); | |
| } | |
| () | |
| ('refresh-token') | |
| ({ summary: 'Refresh access token' }) | |
| async refreshToken(() refreshTokenDto: UserRefreshTokenDto) { | |
| return this.userAuthService.refreshToken(refreshTokenDto); | |
| } | |
| () | |
| ('profile') | |
| ({ summary: 'Get user profile' }) | |
| async getProfile(() sessionData: UserSessionType) { | |
| return { user: sessionData.user }; | |
| } | |
| } | |