🚧 AuthController with multiple endpoints

ref #12
This commit is contained in:
Philipp Dormann 2020-12-05 12:28:43 +01:00
parent d23ed002b2
commit 28c2b862f0
1 changed files with 17 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { InvalidCredentialsError, PasswordNeededError, UsernameOrEmailNeededError } from '../errors/AuthError';
import { UserNotFoundError } from '../errors/UserErrors';
import { CreateAuth } from '../models/creation/CreateAuth';
import { RefreshAuth } from '../models/creation/RefreshAuth';
@JsonController('/auth')
export class AuthController {
@ -16,7 +17,7 @@ export class AuthController {
@ResponseSchema(PasswordNeededError)
@ResponseSchema(InvalidCredentialsError)
@OpenAPI({ description: 'Create a new access token object' })
async post(@Body({ validate: true }) createAuth: CreateAuth) {
async login(@Body({ validate: true }) createAuth: CreateAuth) {
let auth;
try {
auth = await createAuth.toAuth();
@ -26,4 +27,19 @@ export class AuthController {
}
return auth
}
@Post("/refresh")
@ResponseSchema(InvalidCredentialsError)
@ResponseSchema(UserNotFoundError)
@OpenAPI({ description: 'refresh a access token' })
async refresh(@Body({ validate: true }) refreshAuth: RefreshAuth) {
let auth;
try {
auth = await refreshAuth.toAuth();
console.log(auth);
} catch (error) {
return error;
}
return auth
}
}