refactor: resolve #7139

This commit is contained in:
syuilo
2021-02-13 15:33:38 +09:00
parent ebadd7fd3f
commit 91172654e4
76 changed files with 107 additions and 221 deletions

View File

@@ -10,7 +10,6 @@ import signin from '../common/signin';
import { fetchMeta } from '../../../misc/fetch-meta';
import { Users, UserProfiles } from '../../../models';
import { ILocalUser } from '../../../models/entities/user';
import { ensure } from '../../../prelude/ensure';
function getUserToken(ctx: Koa.Context) {
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
@@ -41,12 +40,12 @@ router.get('/disconnect/github', async ctx => {
return;
}
const user = await Users.findOne({
const user = await Users.findOneOrFail({
host: null,
token: userToken
}).then(ensure);
});
const profile = await UserProfiles.findOne(user.id).then(ensure);
const profile = await UserProfiles.findOneOrFail(user.id);
delete profile.integrations.github;
@@ -227,12 +226,12 @@ router.get('/gh/cb', async ctx => {
return;
}
const user = await Users.findOne({
const user = await Users.findOneOrFail({
host: null,
token: userToken
}).then(ensure);
});
const profile = await UserProfiles.findOne(user.id).then(ensure);
const profile = await UserProfiles.findOneOrFail(user.id);
await UserProfiles.update(user.id, {
integrations: {