clockworklabs/SpacetimeDB · error · anyhow::Error

You need to be logged in as the owner of {name} to publish t

Error message

You need to be logged in as the owner of {name} to publish to {name}

What it means

The server answered the publish request with `PublishResult::PermissionDenied { name }`, and the CLI is running anonymously — no login token is stored, so `anon_identity` is true. Because an anonymous identity can never own a named database, the CLI immediately bails with this message instead of trying to decode an identity from a nonexistent token.

Source

Thrown at crates/cli/src/subcommands/publish.rs:663

                let op = match op {
                    PublishOp::Created => "Created new",
                    PublishOp::Updated => "Updated",
                };
                if let Some(ref domain) = domain {
                    println!("{op} database with name: {domain}, identity: {database_identity}");
                } else {
                    println!("{op} database with identity: {database_identity}");
                }

                if is_maincloud_host(&database_host)
                    && let Some(domain) = domain.as_ref()
                {
                    println!("Dashboard: https://spacetimedb.com/{}", domain.as_ref());
                }
            }
            PublishResult::PermissionDenied { name } => {
                if anon_identity {
                    anyhow::bail!("You need to be logged in as the owner of {name} to publish to {name}",);
                }
                // If we're not in the `anon_identity` case, then we have already forced the user to log in above (using `get_auth_header`), so this should be safe to unwrap.
                let token = config.spacetimedb_token().unwrap();
                let identity = decode_identity(token)?;
                //TODO(jdetter): Have a nice name generator here, instead of using some abstract characters
                // we should perhaps generate fun names like 'green-fire-dragon' instead
                let suggested_tld: String = identity.chars().take(12).collect();
                return Err(anyhow::anyhow!(
                    "The database {name} is not registered to the identity you provided.\n\
                    We suggest you push to either a domain owned by you, or a new domain like:\n\
                    \tspacetime publish {suggested_tld}\n",
                ));
            }
        }
    }

    Ok(())
}

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Run `spacetime login` and retry the publish
  2. Confirm who you are with `spacetime identity show` and verify it matches the owning account
  3. If the database belongs to someone else, publish under your own new domain name instead
  4. Check `spacetime server list` to make sure you are publishing to the server where you actually own the database

Example fix

# before
spacetime publish mydb -s maincloud   # PermissionDenied, anon
# after
spacetime login
spacetime publish mydb -s maincloud
Defensive patterns

Strategy: try-catch

Validate before calling

# Fail fast before publishing if not logged in
spacetime identity show >/dev/null 2>&1 || { echo 'not logged in'; spacetime login; }

Try / catch

// Wrapping the publish call in a script/pipe: detect the auth case and route to login
let out = run_cli("spacetime publish db");
if out.contains("You need to be logged in") {
    run_cli("spacetime login"); // interactive
    out = run_cli("spacetime publish db");
}

Prevention

When it happens

Trigger: Publishing to a named database (e.g. `spacetime publish mydb -s maincloud`) that is registered to some other identity while `config.spacetimedb_token()` is absent — fresh install, after `spacetime logout`, or a cleared config directory.

Common situations: New machine or container without prior `spacetime login`; publishing to a domain name claimed by a teammate or another account; assuming the CLI is logged in after reinstalling.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/2acd1ae14de91e86. Report an issue: GitHub.