26
src/controllers/AuthController.ts
Normal file
26
src/controllers/AuthController.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Body, JsonController, Post } from 'routing-controllers';
|
||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||
import { InvalidCredentialsError } from '../errors/AuthError';
|
||||
import { UserNotFoundError } from '../errors/UserErrors';
|
||||
import { CreateAuth } from '../models/creation/CreateAuth';
|
||||
|
||||
@JsonController('/auth')
|
||||
export class AuthController {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
@Post("/login")
|
||||
@ResponseSchema(InvalidCredentialsError)
|
||||
@ResponseSchema(UserNotFoundError)
|
||||
@OpenAPI({ description: 'Create a new access token object' })
|
||||
async post(@Body({ validate: true }) createAuth: CreateAuth) {
|
||||
let auth;
|
||||
try {
|
||||
auth = await createAuth.toAuth();
|
||||
console.log(auth);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
return auth
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user