fix(api/private/auth): wait for error

Previously, the `logout` method immediately returned and did not wait
for the possible error callback.

This wraps the call to `session.destroy` into a promise,
so the error can be properly handled.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-03-04 17:57:55 +01:00
parent 72c354d5f6
commit a32d9e8305

View file

@ -85,12 +85,16 @@ export class AuthController {
@UseGuards(SessionGuard) @UseGuards(SessionGuard)
@Delete('logout') @Delete('logout')
@OpenApi(204, 400, 401) @OpenApi(204, 400, 401)
logout(@Req() request: Request & { session: Session }): void { logout(@Req() request: Request & { session: Session }): Promise<void> {
request.session.destroy((err) => { return new Promise((resolve, reject) => {
if (err) { request.session.destroy((err) => {
this.logger.error('Encountered an error while logging out: ${err}'); if (err) {
throw new BadRequestException('Unable to log out'); this.logger.error('Encountered an error while logging out: ${err}');
} reject(new BadRequestException('Unable to log out'));
} else {
resolve();
}
});
}); });
} }
} }