server: fix logout

pull/84/head
fantasticit 2022-06-17 22:12:19 +08:00
parent ae373fbe48
commit fea52025fe
2 changed files with 12 additions and 1 deletions

View File

@ -68,7 +68,13 @@ export class UserController {
@Post(UserApiDefinition.logout.server) @Post(UserApiDefinition.logout.server)
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async logout(@Res({ passthrough: true }) response: ExpressResponse) { async logout(@Res({ passthrough: true }) response: ExpressResponse) {
response.cookie('token', '', { expires: new Date() }); const { token, domain } = await this.userService.logout();
response.cookie('token', token, {
expires: new Date(),
domain,
httpOnly: true,
sameSite: 'lax',
});
return; return;
} }

View File

@ -132,6 +132,11 @@ export class UserService {
return { user: res, token, domain, expiresIn }; return { user: res, token, domain, expiresIn };
} }
async logout() {
const domain = this.confifgService.get('client.siteDomain');
return { token: '', domain };
}
async validateUser(user: UserEntity) { async validateUser(user: UserEntity) {
return await this.findById(user.id); return await this.findById(user.id);
} }