mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 23:24:46 -04:00
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:
parent
72c354d5f6
commit
a32d9e8305
1 changed files with 10 additions and 6 deletions
|
@ -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> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
request.session.destroy((err) => {
|
request.session.destroy((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.logger.error('Encountered an error while logging out: ${err}');
|
this.logger.error('Encountered an error while logging out: ${err}');
|
||||||
throw new BadRequestException('Unable to log out');
|
reject(new BadRequestException('Unable to log out'));
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue