From abff66eada7b2c0a88a9769338d2d08eaba3fc17 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:18:45 -0800 Subject: [PATCH] fix: :bug: first user gets admin Closes #9620 Co-authored-by: @Johann150 --- packages/backend/src/server/api/common/signup.ts | 1 + .../backend/src/server/api/endpoints/admin/accounts/create.ts | 1 + packages/backend/src/server/api/endpoints/meta.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/backend/src/server/api/common/signup.ts b/packages/backend/src/server/api/common/signup.ts index 7ae9e10fba..bb178506b7 100644 --- a/packages/backend/src/server/api/common/signup.ts +++ b/packages/backend/src/server/api/common/signup.ts @@ -107,6 +107,7 @@ export async function signup(opts: { isAdmin: (await Users.countBy({ host: IsNull(), + isAdmin: true, })) === 0, }), ); diff --git a/packages/backend/src/server/api/endpoints/admin/accounts/create.ts b/packages/backend/src/server/api/endpoints/admin/accounts/create.ts index 11ef2273ca..2e035d1695 100644 --- a/packages/backend/src/server/api/endpoints/admin/accounts/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/accounts/create.ts @@ -35,6 +35,7 @@ export default define(meta, paramDef, async (ps, _me) => { const noUsers = (await Users.countBy({ host: IsNull(), + isAdmin: true, })) === 0; if (!(noUsers || me?.isAdmin)) throw new Error("access denied"); diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 005d0800ac..476a0c29f0 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -489,6 +489,7 @@ export default define(meta, paramDef, async (ps, me) => { requireSetup: (await Users.countBy({ host: IsNull(), + isAdmin: true, })) === 0, } : {}),