Skip to content

superAdmin first login requires invite code but shows 'already a space member' error — no default space seeded #105

@dolphinsboy

Description

@dolphinsboy

Problem

After a fresh deployment, superAdmin can authenticate successfully via POST /v1/user/login and POST /v1/manager/login, but the web client redirects to an invite-code entry page because no Space exists for the admin user.

When the admin tries to enter any invite code, the error "你已经是该空间成员" (already a space member) is returned — creating a catch-22: the UI demands an invite code to proceed, but the invite/join flow rejects the user as already a member.

Reproduction (fresh Docker Compose deployment)

# 1. Fresh deploy
git clone https://github.com/Mininglamp-OSS/octo-deployment.git
cd octo-deployment
./setup.sh --non-interactive --ip 127.0.0.1
cd docker && docker compose --env-file .env up -d

# 2. Verify superAdmin token works
curl -s -X POST http://127.0.0.1:28081/v1/user/login \
  -H 'Content-Type: application/json' \
  -d '{"username":"superAdmin","password":"<OCTO_ADMIN_PWD>"}' | jq .
# → returns valid token ✅

# 3. Check spaces for superAdmin
curl -s http://127.0.0.1:28081/v1/space/my -H "token: <token>"
# → [] (empty array — no spaces) ✅ explains web redirect

# 4. Open web UI: http://127.0.0.1:28080
# → Login with superAdmin / <OCTO_ADMIN_PWD>
# → Redirected to invite-code entry page ❌
# → Enter any invite code → "你已经是该空间成员" ❌

Root Cause (source analysis)

1. superAdmin is seeded without a Space

createManagerAccount() in modules/user/api_manager.go only creates the user row — it does not create a default Space or add the admin as a member of any Space:

func (m *Manager) createManagerAccount() {
    // Only inserts a User row (UID, name, role=superAdmin, ...)
    // No space creation, no space membership
    err = m.userDB.Insert(&Model{ ... })
}

2. Web client: empty Space list → invite-code redirect

GET /v1/space/my returns [] for superAdmin → web treats this as "not in any space" → redirects to invite-code entry.

3. joinSpace catches ErrAlreadyMember but space doesn't exist

The joinSpace handler in modules/space/api.go (line ~873) returns "你已经是该空间成员" via ErrAlreadyMember. This appears to be triggered even when GET /v1/space/list returns "空间不存在" — suggesting a data inconsistency between the space membership table and the spaces table after the initial seed.

Expected Behavior

After fresh deployment:

  • Option A: createManagerAccount() automatically creates a default Space and adds superAdmin as owner → web client lands directly on the main UI
  • Option B: Web client detects role == superAdmin with no spaces and shows a "Create your first Space" onboarding flow instead of an invite-code entry page
  • Either way: the invite-code catch-22 ("enter code" + "already member" error) must not occur

Environment

  • octo-server: latest (mininglamposs/octo-server Docker image)
  • octo-deployment: main
  • Fresh Docker Compose deployment on macOS

Additional Notes

  • superAdmin can log in to the Admin console (http://127.0.0.1:28080/admin/) without any issue
  • The problem is specific to the Web client first-login flow
  • GET /v1/manager/login works correctly for admin console use cases
  • The catch-22 completely blocks superAdmin from accessing the web client on a fresh install

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P1High — this sprinttype:bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions