Files
yara724api/src/auth/auth-controllers/user/user.auth.controller.ts
2026-06-03 11:34:21 +03:30

51 lines
1.4 KiB
TypeScript

import {
Body,
Controller,
HttpException,
HttpStatus,
Post,
Req,
UseGuards,
} from "@nestjs/common";
import { ApiAcceptedResponse, ApiBody, ApiTags } from "@nestjs/swagger";
import { UserAuthService } from "src/auth/auth-services/user.auth.service";
import { UserLoginDto } from "src/auth/dto/user/login.dto";
import { UserVerifyOtp } from "src/auth/dto/user/verify.dto";
import { LocalUserAuthGuard } from "src/auth/guards/user-local.guard";
import { CurrentUser } from "src/decorators/user.decorator";
@Controller("user")
@ApiTags("user")
export class UserAuthController {
constructor(private readonly userAuthService: UserAuthService) {}
@Post("/send-otp")
@ApiBody({
type: UserLoginDto,
description: "Users can ask for OTP via this API and receive it",
})
@ApiAcceptedResponse()
async sendOtpRq(@Body() body: UserLoginDto) {
const res = await this.userAuthService.sendOtpRequest(body.mobile, {
linkToken: body.linkToken,
linkContext: body.linkContext,
});
if (res) {
throw new HttpException(res, HttpStatus.ACCEPTED);
}
}
@Post("/login")
@UseGuards(LocalUserAuthGuard)
@ApiBody({
type: UserVerifyOtp,
description:
"Users can send their credentials and get their access token to server",
})
@ApiAcceptedResponse()
async login(@Body() body, @Req() req, @CurrentUser() user) {
return await this.userAuthService.login(req.user);
}
}