What version of Wrangler are you using?
4.122.0
What operating system are you using?
macOS
Describe the Bug
wrangler d1 migrations apply --remote --temporary fails with:
X [ERROR] You're already authenticated with Cloudflare, so `--temporary` can't be used. Temporary preview accounts are only for unauthenticated use. Either remove `--temporary` to use your existing account, or log out (and unset CLOUDFLARE_API_TOKEN) first.
...even when the only prior interaction with --temporary in the session was wrangler d1 create <name> --temporary and wrangler kv namespace create <name> --temporary, run against a freshly-created temp preview account (no wrangler login was ever run, and CLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID were not set in the environment).
The auth check for d1 migrations apply appears to treat the cached temp-account credential file at ~/Library/Preferences/.wrangler/wrangler-temporary-account.toml (written by earlier --temporary commands in the same session) as evidence of a real login, and refuses to proceed — even though --temporary is explicitly passed on this exact invocation and no real wrangler login ever happened.
Steps to reproduce
- In a clean environment with no prior
wrangler login and no CLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID set:
wrangler deploy --temporary
(accept the resulting temp preview account claim)
- Create a D1 database against the same temp account:
wrangler d1 create my-db --temporary
- Apply migrations to that database, still passing
--temporary:
wrangler d1 migrations apply my-db --remote --temporary
Expected
Migrations apply against the temp preview account's D1 instance, same as the create/deploy commands did.
Actual
Fails immediately with You're already authenticated with Cloudflare, so --temporary can't be used, even though no real login exists — only cached temp-account state from steps 1-2 in the same session.
Workaround found
Extract account.id and apiToken from the cached ~/Library/Preferences/.wrangler/wrangler-temporary-account.toml, export them as CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN, then run the migrations command without --temporary:
export CLOUDFLARE_ACCOUNT_ID=<account.id from the toml file>
export CLOUDFLARE_API_TOKEN=<apiToken from the toml file>
wrangler d1 migrations apply my-db --remote
This applies cleanly against the real remote D1 instance tied to the temp account. It works, but it means --temporary is functionally unsupported for the d1 migrations apply --remote subcommand specifically, unlike d1 create, kv namespace create, and deploy, which all correctly accept --temporary in the same session.
Relevant code
The check appears to live around wrangler-dist/cli.js's "already authenticated" telemetry message (user temporary account already authenticated), which doesn't seem to special-case d1 migrations apply's own --temporary flag the way sibling commands do.
What version of Wrangler are you using?
4.122.0
What operating system are you using?
macOS
Describe the Bug
wrangler d1 migrations apply --remote --temporaryfails with:...even when the only prior interaction with
--temporaryin the session waswrangler d1 create <name> --temporaryandwrangler kv namespace create <name> --temporary, run against a freshly-created temp preview account (nowrangler loginwas ever run, andCLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_IDwere not set in the environment).The auth check for
d1 migrations applyappears to treat the cached temp-account credential file at~/Library/Preferences/.wrangler/wrangler-temporary-account.toml(written by earlier--temporarycommands in the same session) as evidence of a real login, and refuses to proceed — even though--temporaryis explicitly passed on this exact invocation and no realwrangler loginever happened.Steps to reproduce
wrangler loginand noCLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_IDset:--temporary:Expected
Migrations apply against the temp preview account's D1 instance, same as the
create/deploycommands did.Actual
Fails immediately with
You're already authenticated with Cloudflare, so --temporary can't be used, even though no real login exists — only cached temp-account state from steps 1-2 in the same session.Workaround found
Extract
account.idandapiTokenfrom the cached~/Library/Preferences/.wrangler/wrangler-temporary-account.toml, export them asCLOUDFLARE_ACCOUNT_IDandCLOUDFLARE_API_TOKEN, then run the migrations command without--temporary:This applies cleanly against the real remote D1 instance tied to the temp account. It works, but it means
--temporaryis functionally unsupported for thed1 migrations apply --remotesubcommand specifically, unliked1 create,kv namespace create, anddeploy, which all correctly accept--temporaryin the same session.Relevant code
The check appears to live around wrangler-dist/cli.js's "already authenticated" telemetry message (
user temporary account already authenticated), which doesn't seem to special-cased1 migrations apply's own--temporaryflag the way sibling commands do.