mirror of
https://git.meshkee.com/Meshkee/backend.git
synced 2026-08-11 22:30:59 +04:30
Same-password register joins silently; mismatched password explains the existing Meshkee account; login/OTP with domain attaches business membership. Co-authored-by: Cursor <cursoragent@cursor.com>
125 lines
3.3 KiB
TypeScript
125 lines
3.3 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { CurrentUser } from './decorators/current-user.decorator';
|
|
import { ChangePasswordDto } from './dto/change-password.dto';
|
|
import { LoginDto } from './dto/login.dto';
|
|
import { LoginOtpDto } from './dto/login-otp.dto';
|
|
import { RefreshTokenDto } from './dto/refresh-token.dto';
|
|
import { RegisterDto } from './dto/register.dto';
|
|
import { ResetPasswordDto } from './dto/reset-password.dto';
|
|
import { SendOtpDto } from './dto/send-otp.dto';
|
|
import { UpdateProfileDto } from './dto/update-profile.dto';
|
|
import { UpsertUserAddressDto } from './dto/upsert-user-address.dto';
|
|
import { VerifyOtpDto } from './dto/verify-otp.dto';
|
|
import { JwtAuthGuard } from './guards/jwt-auth.guard';
|
|
import { AuthUser } from './auth.types';
|
|
import { UserAddressesService } from './user-addresses.service';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(
|
|
private readonly authService: AuthService,
|
|
private readonly userAddresses: UserAddressesService,
|
|
) {}
|
|
|
|
@Post('register')
|
|
register(@Body() dto: RegisterDto) {
|
|
return this.authService.register(dto);
|
|
}
|
|
|
|
@Post('login')
|
|
login(@Body() dto: LoginDto) {
|
|
return this.authService.login(dto);
|
|
}
|
|
|
|
@Post('login-otp')
|
|
loginWithOtp(@Body() dto: LoginOtpDto) {
|
|
return this.authService.loginWithOtp(dto.cellNumber, dto.code, dto.domain);
|
|
}
|
|
|
|
@Post('reset-password')
|
|
resetPassword(@Body() dto: ResetPasswordDto) {
|
|
return this.authService.resetPassword(
|
|
dto.cellNumber,
|
|
dto.code,
|
|
dto.newPassword,
|
|
);
|
|
}
|
|
|
|
@Post('refresh')
|
|
refresh(@Body() dto: RefreshTokenDto) {
|
|
return this.authService.refresh(dto.refreshToken);
|
|
}
|
|
|
|
@Get('me')
|
|
@UseGuards(JwtAuthGuard)
|
|
me(@CurrentUser() user: AuthUser) {
|
|
return this.authService.me(user);
|
|
}
|
|
|
|
@Patch('profile')
|
|
@UseGuards(JwtAuthGuard)
|
|
updateProfile(@CurrentUser() user: AuthUser, @Body() dto: UpdateProfileDto) {
|
|
return this.authService.updateProfile(user, dto);
|
|
}
|
|
|
|
@Post('change-password')
|
|
@UseGuards(JwtAuthGuard)
|
|
changePassword(@CurrentUser() user: AuthUser, @Body() dto: ChangePasswordDto) {
|
|
return this.authService.changePassword(user, dto);
|
|
}
|
|
|
|
@Post('send-otp')
|
|
sendOtp(@Body() dto: SendOtpDto) {
|
|
return this.authService.sendOtp(dto.cellNumber, dto.domain);
|
|
}
|
|
|
|
@Post('verify-otp')
|
|
verifyOtp(@Body() dto: VerifyOtpDto) {
|
|
return this.authService.verifyOtp(dto.cellNumber, dto.code);
|
|
}
|
|
|
|
@Get('addresses')
|
|
@UseGuards(JwtAuthGuard)
|
|
listAddresses(@CurrentUser() user: AuthUser) {
|
|
return this.userAddresses.list(user);
|
|
}
|
|
|
|
@Post('addresses')
|
|
@UseGuards(JwtAuthGuard)
|
|
createAddress(
|
|
@CurrentUser() user: AuthUser,
|
|
@Body() dto: UpsertUserAddressDto,
|
|
) {
|
|
return this.userAddresses.create(user, dto);
|
|
}
|
|
|
|
@Patch('addresses/:addressId')
|
|
@UseGuards(JwtAuthGuard)
|
|
updateAddress(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('addressId') addressId: string,
|
|
@Body() dto: UpsertUserAddressDto,
|
|
) {
|
|
return this.userAddresses.update(user, addressId, dto);
|
|
}
|
|
|
|
@Delete('addresses/:addressId')
|
|
@UseGuards(JwtAuthGuard)
|
|
removeAddress(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('addressId') addressId: string,
|
|
) {
|
|
return this.userAddresses.remove(user, addressId);
|
|
}
|
|
}
|