diff --git a/packages/hydrooj/src/handler/user.ts b/packages/hydrooj/src/handler/user.ts index c3d6b7cb6..c96431b55 100644 --- a/packages/hydrooj/src/handler/user.ts +++ b/packages/hydrooj/src/handler/user.ts @@ -476,12 +476,19 @@ class OauthCallbackHandler extends Handler { return; } - const uid = await this.ctx.oauth.get(args.type, r._id) || await this.ctx.oauth.get('mail', r.email); + const uid = await this.ctx.oauth.get(args.type, r._id); if (uid) { await successfulAuth.call(this, await user.getById('system', uid)); this.response.redirect = '/'; return; } + const udoc = await user.getByEmail('system', r.email); + if (udoc) { + await this.ctx.oauth.set(args.type, r._id, udoc._id); + await successfulAuth.call(this, udoc); + this.response.redirect = '/'; + return; + } if (!provider.canRegister) throw new ForbiddenError('No binded account found'); this.checkPriv(PRIV.PRIV_REGISTER_USER); let username = '';