Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/auth/google/google.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,28 @@ export class GoogleService {
}

if (userId) {
const wechatUser = await this.userService.findByLoginId(userData.sub);
if (wechatUser && wechatUser.id !== userId) {
const providerName = this.i18n.t('auth.providers.google');
const message = this.i18n.t('auth.errors.invalidProviderData', {
args: { provider: providerName },
});
throw new AppException(
message,
'ACCOUNT_ALREADY_BOUND',
HttpStatus.BAD_REQUEST,
);
const googleUser = await this.userService.findByLoginId(userData.sub);
if (googleUser) {
if (googleUser.id !== userId) {
const providerName = this.i18n.t('auth.providers.google');
const message = this.i18n.t('auth.errors.invalidProviderData', {
args: { provider: providerName },
});
throw new AppException(
message,
'ACCOUNT_ALREADY_BOUND',
HttpStatus.BAD_REQUEST,
);
}
const returnValue = {
id: googleUser.id,
access_token: this.jwtService.sign({
sub: googleUser.id,
}),
};
stateInfo.userInfo = returnValue;
await this.socialService.updateState(state, stateInfo);
return returnValue;
}
const existingUser = await this.userService.bindingExistUser({
userId,
Expand Down
31 changes: 21 additions & 10 deletions src/auth/wechat/wechat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,27 @@ export class WechatService {

if (userId) {
const wechatUser = await this.userService.findByLoginId(userData.unionid);
if (wechatUser && wechatUser.id !== userId) {
const providerName = this.i18n.t('auth.providers.wechat');
const message = this.i18n.t('auth.errors.invalidProviderData', {
args: { provider: providerName },
});
throw new AppException(
message,
'ACCOUNT_ALREADY_BOUND',
HttpStatus.BAD_REQUEST,
);
if (wechatUser) {
if (wechatUser.id !== userId) {
const providerName = this.i18n.t('auth.providers.wechat');
const message = this.i18n.t('auth.errors.invalidProviderData', {
args: { provider: providerName },
});
throw new AppException(
message,
'ACCOUNT_ALREADY_BOUND',
HttpStatus.BAD_REQUEST,
);
}
const returnValue = {
id: wechatUser.id,
access_token: this.jwtService.sign({
sub: wechatUser.id,
}),
};
stateInfo.userInfo = returnValue;
await this.socialService.updateState(state, stateInfo);
return returnValue;
}
const existingUser = await this.userService.bindingExistUser({
userId,
Expand Down