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 + } }