0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

refactor(core): update first admin user preconditions (#5858)

This commit is contained in:
Gao Sun 2024-05-14 14:12:07 +08:00 committed by GitHub
parent f020c5984c
commit 304d948511
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -86,6 +86,7 @@ const getInitialUserRoles = (
isCreatingFirstAdminUser && !isCloud && defaultManagementApiAdminName // OSS uses the legacy Management API user role
);
// eslint-disable-next-line complexity -- @simeng refactor me
async function handleSubmitRegister(
interaction: VerifiedRegisterInteractionResult,
ctx: WithLogContext & WithInteractionDetailsContext & WithInteractionHooksContext,
@ -113,8 +114,15 @@ async function handleSubmitRegister(
const { isCloud } = EnvSet.values;
const [currentTenantId] = await getTenantId(ctx.URL);
const isInAdminTenant = currentTenantId === adminTenantId;
/**
* Only allow creating the first admin user when it's in OSS or integration tests to avoid
* security issues.
*/
const isCreatingFirstAdminUser =
isInAdminTenant && String(client_id) === adminConsoleApplicationId && !(await hasActiveUsers());
(!EnvSet.values.isCloud || EnvSet.values.isIntegrationTest) &&
isInAdminTenant &&
String(client_id) === adminConsoleApplicationId &&
!(await hasActiveUsers());
// If it's Logto Cloud, Check if the new user has any pending invitations, if yes, skip onboarding flow.
const invitations =