From 6a732ab1cd5397a523c10d3b7f32a22c23697a1e Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 31 Mar 2020 08:07:10 +0900 Subject: [PATCH] Fix #6203 --- src/server/api/common/signup.ts | 6 +++--- src/server/api/endpoints/admin/accounts/create.ts | 4 +++- src/server/api/endpoints/meta.ts | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/server/api/common/signup.ts b/src/server/api/common/signup.ts index b6e13b36f..26a9d03e0 100644 --- a/src/server/api/common/signup.ts +++ b/src/server/api/common/signup.ts @@ -22,8 +22,6 @@ export async function signup(username: User['username'], password: UserProfile[' throw new Error('INVALID_PASSWORD'); } - const usersCount = await Users.count({}); - // Generate hash of password const salt = await bcrypt.genSalt(8); const hash = await bcrypt.hash(password, salt); @@ -76,7 +74,9 @@ export async function signup(username: User['username'], password: UserProfile[' usernameLower: username.toLowerCase(), host: toPunyNullable(host), token: secret, - isAdmin: usersCount === 0, + isAdmin: (await Users.count({ + host: null, + })) === 0, })); await transactionalEntityManager.save(new UserKeypair({ diff --git a/src/server/api/endpoints/admin/accounts/create.ts b/src/server/api/endpoints/admin/accounts/create.ts index ac80b579b..9d4712e72 100644 --- a/src/server/api/endpoints/admin/accounts/create.ts +++ b/src/server/api/endpoints/admin/accounts/create.ts @@ -17,7 +17,9 @@ export const meta = { }; export default define(meta, async (ps, me) => { - const noUsers = (await Users.count({})) === 0; + const noUsers = (await Users.count({ + host: null, + })) === 0; if (!noUsers && me == null) throw new Error('access denied'); const { account, secret } = await signup(ps.username, ps.password); diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index 41adc855d..0cb6f75f1 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -137,7 +137,9 @@ export default define(meta, async (ps, me) => { category: e.category, url: e.url, })), - requireSetup: (await Users.count({})) === 0, + requireSetup: (await Users.count({ + host: null, + })) === 0, enableEmail: instance.enableEmail, enableTwitterIntegration: instance.enableTwitterIntegration,