diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 1dc280c858..434a6349de 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -747,9 +747,12 @@ async def signup( has_users = await Users.has_users(db=db) if WEBUI_AUTH: - if not request.app.state.config.ENABLE_SIGNUP or not request.app.state.config.ENABLE_LOGIN_FORM: - if has_users or not ENABLE_INITIAL_ADMIN_SIGNUP: + if has_users: + if not request.app.state.config.ENABLE_SIGNUP or not request.app.state.config.ENABLE_LOGIN_FORM: raise HTTPException(status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED) + # Don't gate the first admin on ENABLE_SIGNUP: it auto-disables and can persist stale across a DB reset. + elif not request.app.state.config.ENABLE_LOGIN_FORM and not ENABLE_INITIAL_ADMIN_SIGNUP: + raise HTTPException(status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED) else: if has_users: raise HTTPException(status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.ACCESS_PROHIBITED)