🚧 implementation in AuthController@login

ref #25
This commit is contained in:
Philipp Dormann 2020-12-12 11:55:45 +01:00
parent 7429407843
commit 36fbccb286
1 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { Body, JsonController, Post } from 'routing-controllers';
import { Body, JsonController, Post, Res } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { IllegalJWTError, InvalidCredentialsError, JwtNotProvidedError, PasswordNeededError, RefreshTokenCountInvalidError, UsernameOrEmailNeededError } from '../errors/AuthError';
import { UserNotFoundError } from '../errors/UserErrors';
@ -21,10 +21,13 @@ export class AuthController {
@ResponseSchema(PasswordNeededError)
@ResponseSchema(InvalidCredentialsError)
@OpenAPI({ description: 'Create a new access token object' })
async login(@Body({ validate: true }) createAuth: CreateAuth) {
async login(@Body({ validate: true }) createAuth: CreateAuth, @Res() response: any) {
let auth;
try {
auth = await createAuth.toAuth();
response.cookie('lfk_backend__refresh_token', auth.refresh_token, { maxAge: 900000, httpOnly: true });
response.cookie('lfk_backend__refresh_token_expires_at', auth.refresh_token_expires_at, { maxAge: 900000, httpOnly: true });
return response.send(auth)
} catch (error) {
throw error;
}