mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-25 14:02:30 +00: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)
|
||||
@Delete('logout')
|
||||
@OpenApi(204, 400, 401)
|
||||
logout(@Req() request: Request & { session: Session }): void {
|
||||
request.session.destroy((err) => {
|
||||
if (err) {
|
||||
this.logger.error('Encountered an error while logging out: ${err}');
|
||||
throw new BadRequestException('Unable to log out');
|
||||
}
|
||||
logout(@Req() request: Request & { session: Session }): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.session.destroy((err) => {
|
||||
if (err) {
|
||||
this.logger.error('Encountered an error while logging out: ${err}');
|
||||
reject(new BadRequestException('Unable to log out'));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue