Skip to content

Commit

Permalink
[wrangler] fix: check permissions on authentication error with API to…
Browse files Browse the repository at this point in the history
…ken set (#4597)

* fix: check permissions on authentication error with API token set

* Update packages/wrangler/src/index.ts

Co-authored-by: Pete Bacon Darwin <[email protected]>

---------

Co-authored-by: Pete Bacon Darwin <[email protected]>
  • Loading branch information
mrbbot and petebacondarwin committed Jan 2, 2024
1 parent 6fb72f8 commit e1d5040
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/strange-eels-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: suggest checking permissions on authentication error with API token set
3 changes: 3 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8324,6 +8324,9 @@ export default{
Authentication error [code: 10000]
📎 It looks like you are authenticating Wrangler via a custom API token set in an environment variable.
Please ensure it has the correct permissions for this operation.
Getting User settings...
👋 You are logged in with an API Token, associated with the email [email protected]!
┌───────────────┬────────────┐
Expand Down
16 changes: 15 additions & 1 deletion packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import module from "node:module";
import os from "node:os";
import TOML from "@iarna/toml";
import chalk from "chalk";
import { ProxyAgent, setGlobalDispatcher } from "undici";
import makeCLI from "yargs";
import { version as wranglerVersion } from "../package.json";
Expand Down Expand Up @@ -56,7 +57,13 @@ import {
import { tailOptions, tailHandler } from "./tail";
import { generateTypes } from "./type-generation";
import { printWranglerBanner } from "./update-check";
import { listScopes, login, logout, validateScopeKeys } from "./user";
import {
getAuthFromEnv,
listScopes,
login,
logout,
validateScopeKeys,
} from "./user";
import { vectorize } from "./vectorize/index";
import { whoami } from "./whoami";

Expand Down Expand Up @@ -724,6 +731,13 @@ export async function main(argv: string[]): Promise<void> {
await createCLIParser([...argv, "--help"]).parse();
} else if (isAuthenticationError(e)) {
logger.log(formatMessage(e));
const envAuth = getAuthFromEnv();
if (envAuth !== undefined && "apiToken" in envAuth) {
const message =
"📎 It looks like you are authenticating Wrangler via a custom API token set in an environment variable.\n" +
"Please ensure it has the correct permissions for this operation.\n";
logger.log(chalk.yellow(message));
}
await whoami();
} else if (e instanceof ParseError) {
e.notes.push({
Expand Down

0 comments on commit e1d5040

Please sign in to comment.