Skip to content

Instantly share code, notes, and snippets.

@jacobdo2
Created June 17, 2020 12:15
Show Gist options
  • Save jacobdo2/4b33e33ae9576386dd68f3f4fc3784c4 to your computer and use it in GitHub Desktop.
Save jacobdo2/4b33e33ae9576386dd68f3f4fc3784c4 to your computer and use it in GitHub Desktop.
import { BadRequestException, Body, Controller, Post } from '@nestjs/common';
import { AuthService } from './auth.service';
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('register')
async register(
@Body() registerRequest: { name: string; password: string; email: string },
) {
return await this.authService.registerUser(registerRequest)
}
@Post('login')
async login(@Body() authenticateRequest: { name: string; password: string }) {
try {
return await this.authService.authenticateUser(authenticateRequest);
} catch (e) {
throw new BadRequestException(e.message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment