diff --git a/src/auth/google/google.service.ts b/src/auth/google/google.service.ts index 92e989fe..2ee8e916 100644 --- a/src/auth/google/google.service.ts +++ b/src/auth/google/google.service.ts @@ -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, diff --git a/src/auth/wechat/wechat.service.ts b/src/auth/wechat/wechat.service.ts index a60d64f1..a00eed7e 100644 --- a/src/auth/wechat/wechat.service.ts +++ b/src/auth/wechat/wechat.service.ts @@ -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,