From 28c2b862f0a070323ea7eb1d2c0a53c71979e46f Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Sat, 5 Dec 2020 12:28:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20AuthController=20with=20multiple?= =?UTF-8?q?=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #12 --- src/controllers/AuthController.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/controllers/AuthController.ts b/src/controllers/AuthController.ts index afa677b..d14e574 100644 --- a/src/controllers/AuthController.ts +++ b/src/controllers/AuthController.ts @@ -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 + } }