@leeguoo/wrangler-accounts 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/wrangler-accounts.js
CHANGED
|
@@ -695,6 +695,64 @@ function main() {
|
|
|
695
695
|
if (!isValidName(name)) die(`Invalid profile name: ${name}`);
|
|
696
696
|
ensureDir(profilesDir);
|
|
697
697
|
|
|
698
|
+
// Guard 1: refuse to run in a non-interactive context (CI, sub-agent,
|
|
699
|
+
// pipe). 'wrangler login' opens a browser and requires the user to
|
|
700
|
+
// click an authorize button. In a non-TTY context this hangs forever
|
|
701
|
+
// and any attempt is almost certainly an AI/script applying 'login'
|
|
702
|
+
// as if it were idempotent — it isn't.
|
|
703
|
+
if (!process.stdin.isTTY && !opts.force) {
|
|
704
|
+
die(
|
|
705
|
+
[
|
|
706
|
+
`'login' requires an interactive terminal — wrangler will open a browser`,
|
|
707
|
+
`and wait for authorization. Stdin is not a TTY here.`,
|
|
708
|
+
``,
|
|
709
|
+
`If you are an AI agent or script trying to verify a profile is`,
|
|
710
|
+
`working, do NOT use 'login'. Use one of these instead:`,
|
|
711
|
+
``,
|
|
712
|
+
` wrangler-accounts whoami --profile ${name} # static check (meta.json)`,
|
|
713
|
+
` wrangler-accounts list --deep # live check (network call)`,
|
|
714
|
+
``,
|
|
715
|
+
`If you really need to re-authenticate this profile non-interactively,`,
|
|
716
|
+
`pass --force to bypass this guard (the OAuth flow will still need a`,
|
|
717
|
+
`browser to complete).`,
|
|
718
|
+
].join("\n"),
|
|
719
|
+
1,
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// Guard 2: refuse to overwrite an existing profile that's already
|
|
724
|
+
// healthy unless --force is passed. 'login' is destructive — it
|
|
725
|
+
// OVERWRITES the saved profile by design. If the profile is already
|
|
726
|
+
// valid, the caller almost certainly meant to verify, not re-create.
|
|
727
|
+
const existingCfg = path.join(profilesDir, name, "config.toml");
|
|
728
|
+
if (fs.existsSync(existingCfg) && !opts.force) {
|
|
729
|
+
const session = readSessionState(existingCfg);
|
|
730
|
+
const looksHealthy = session.effective === "valid" || session.effective === "refreshable";
|
|
731
|
+
if (looksHealthy) {
|
|
732
|
+
die(
|
|
733
|
+
[
|
|
734
|
+
`Profile '${name}' already exists and looks healthy:`,
|
|
735
|
+
` status: ${session.effective}`,
|
|
736
|
+
` expirationTime: ${session.expirationTime || "(none)"}`,
|
|
737
|
+
` hasRefreshToken: ${session.hasRefreshToken}`,
|
|
738
|
+
``,
|
|
739
|
+
`'login' is DESTRUCTIVE — it opens a browser and overwrites the saved`,
|
|
740
|
+
`profile. If you only wanted to verify the profile works, run instead:`,
|
|
741
|
+
``,
|
|
742
|
+
` wrangler-accounts whoami --profile ${name} # fast, no network`,
|
|
743
|
+
` wrangler-accounts list --deep # authoritative, hits Cloudflare API`,
|
|
744
|
+
``,
|
|
745
|
+
`If you really intend to re-authenticate (e.g. you revoked the token`,
|
|
746
|
+
`in the Cloudflare dashboard, or want to switch which OAuth account`,
|
|
747
|
+
`this profile is bound to), pass --force:`,
|
|
748
|
+
``,
|
|
749
|
+
` wrangler-accounts login ${name} --force`,
|
|
750
|
+
].join("\n"),
|
|
751
|
+
1,
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
698
756
|
// Create a shadow HOME without pre-linking .wrangler/config/default.toml.
|
|
699
757
|
// wrangler login will write a fresh file into shadow/.wrangler/config/
|
|
700
758
|
// which we then move into the profile directory.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leeguoo/wrangler-accounts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Cloudflare Wrangler multi-account manager — save, switch, and run wrangler against multiple Cloudflare Workers accounts with AWS-style --profile and per-invocation shadow HOME isolation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -160,6 +160,34 @@ wrangler-accounts list # confirm the profile is saved
|
|
|
160
160
|
|
|
161
161
|
The login flow runs inside an isolated shadow `HOME`, so the user's real `~/.wrangler/config/default.toml` is never touched.
|
|
162
162
|
|
|
163
|
+
> ⚠️ **`login` is destructive.** It opens a browser, requires the user to click "Authorize" interactively, and **OVERWRITES** the named profile. As of 1.4.0, `wrangler-accounts login <name>` refuses to run if (a) stdin is not a TTY, or (b) the profile already exists and looks healthy — both unless you pass `--force`. **Never run `login` to "verify" or "refresh" a profile** — see the antipattern below.
|
|
164
|
+
|
|
165
|
+
### ❌ Antipattern: running `login` to verify a profile works
|
|
166
|
+
|
|
167
|
+
This is wrong:
|
|
168
|
+
```bash
|
|
169
|
+
wrangler-accounts login Xdreamstar2025 # ❌ DON'T do this just to check
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Reasons:
|
|
173
|
+
1. `login` is **destructive** — it overwrites the saved profile with a brand new OAuth flow.
|
|
174
|
+
2. `login` requires a **browser and an interactive terminal** — it cannot complete in a Bash sub-shell, CI runner, or sub-agent context. The command will hang waiting for the user.
|
|
175
|
+
3. The Cloudflare access token in a healthy profile auto-refreshes via `refresh_token` — there is **nothing to "log in to"** when the profile already works.
|
|
176
|
+
|
|
177
|
+
Use one of these instead:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
wrangler-accounts whoami --profile Xdreamstar2025 # fast, reads meta.json, no network
|
|
181
|
+
wrangler-accounts list --deep # authoritative, runs wrangler whoami per profile
|
|
182
|
+
wrangler-accounts list # quick STATUS overview (valid / valid* / EXPIRED / unknown)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Only fall back to `wrangler-accounts login <name>` when:
|
|
186
|
+
- The profile **does not exist yet** (creating a new account profile from scratch)
|
|
187
|
+
- The profile shows `EXPIRED` (truly expired, no refresh_token left) — see STATUS table above
|
|
188
|
+
- `list --deep` returns `✗` with "Not logged in" / "refresh token may be revoked" (server-side revocation)
|
|
189
|
+
- The user **explicitly says** "re-authenticate this profile" / "log me in again"
|
|
190
|
+
|
|
163
191
|
### User wants: check which account a profile is tied to, without running wrangler
|
|
164
192
|
|
|
165
193
|
```bash
|