fix: 修复用户删除后,用相同的oauth授权登录报错用户不存在的问题

https://github.com/certd/certd/issues/603
This commit is contained in:
xiaojunnuo
2025-12-19 11:37:22 +08:00
parent 31f09ab117
commit e505916525
2 changed files with 11 additions and 1 deletions

View File

@@ -242,7 +242,9 @@ export class LoginService {
}
const info = await this.userService.findOne({id: oauthBound.userId});
if (info == null) {
throw new CommonException('用户不存在');
// 用户已被删除删除此oauth绑定
await this.oauthBoundService.delete([oauthBound.id]);
return null
}
return this.generateToken(info);
}

View File

@@ -13,6 +13,7 @@ import { RandomUtil } from '../../../../utils/random.js';
import dayjs from 'dayjs';
import { DbAdapter } from '../../../db/index.js';
import { simpleNanoId, utils } from '@certd/basic';
import { OauthBoundService } from '../../../login/service/oauth-bound-service.js';
export type RegisterType = 'username' | 'mobile' | 'email';
export type ForgotPasswordType = 'mobile' | 'email';
@@ -42,6 +43,10 @@ export class UserService extends BaseService<UserEntity> {
@Inject()
dbAdapter: DbAdapter;
@Inject()
oauthBoundService: OauthBoundService;
//@ts-ignore
getRepository() {
return this.repository;
@@ -311,6 +316,9 @@ export class UserService extends BaseService<UserEntity> {
throw new CommonException('不能删除管理员');
}
await super.delete(ids);
await this.oauthBoundService.deleteWhere({
userId: In(ids),
});
}
async isAdmin(userId: any) {