Files
swiss-datashare/backend/src/auth/auth.controller.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

import {
Body,
Controller,
ForbiddenException,
HttpCode,
Post,
} from "@nestjs/common";
2022-10-24 12:11:10 +02:00
import { Throttle } from "@nestjs/throttler";
import { ConfigService } from "src/config/config.service";
import { AuthService } from "./auth.service";
import { AuthRegisterDTO } from "./dto/authRegister.dto";
2022-10-10 17:58:42 +02:00
import { AuthSignInDTO } from "./dto/authSignIn.dto";
import { RefreshAccessTokenDTO } from "./dto/refreshAccessToken.dto";
@Controller("auth")
export class AuthController {
constructor(
private authService: AuthService,
private config: ConfigService
) {}
2022-10-24 12:11:10 +02:00
@Throttle(10, 5 * 60)
@Post("signUp")
async signUp(@Body() dto: AuthRegisterDTO) {
if (!this.config.get("allowRegistration"))
throw new ForbiddenException("Registration is not allowed");
return this.authService.signUp(dto);
}
2022-10-24 12:11:10 +02:00
@Throttle(10, 5 * 60)
@Post("signIn")
2022-10-13 23:23:33 +02:00
@HttpCode(200)
2022-10-10 17:58:42 +02:00
signIn(@Body() dto: AuthSignInDTO) {
return this.authService.signIn(dto);
}
@Post("token")
@HttpCode(200)
async refreshAccessToken(@Body() body: RefreshAccessTokenDTO) {
const accessToken = await this.authService.refreshAccessToken(
body.refreshToken
);
return { accessToken };
}
}