mirror of https://github.com/fantasticit/think.git
server: fix logout
This commit is contained in:
parent
ae373fbe48
commit
fea52025fe
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue