auth.controller.ts 516 B

12345678910111213141516171819
  1. import { Body, Controller, Post } from "@nestjs/common";
  2. import { LoginDto } from "./login.dto";
  3. import { AuthService } from "../../auth/auth.service";
  4. @Controller('auth')
  5. export class AuthController {
  6. constructor(private authService: AuthService) {}
  7. @Post('login')
  8. async login(@Body() loginDto: LoginDto) {
  9. const token = await this.authService.createToken(loginDto.username, loginDto.password);
  10. if (token) {
  11. return {
  12. token
  13. };
  14. }
  15. }
  16. }