Skip to content

add auth profiles to wrangler #13975

Closed
emily-shen wants to merge 16 commits into
mainfrom
emily/profiles
Closed

add auth profiles to wrangler #13975
emily-shen wants to merge 16 commits into
mainfrom
emily/profiles

Conversation

@emily-shen

@emily-shen emily-shen commented May 19, 2026

Copy link
Copy Markdown
Contributor

Supersedes #11780

'Profiles' are essentially just Oauth tokens that you can switch between without re-authing. The main change compared to the earlier PR is that you can now bind a profile to a particular directory.

New commands/flags

  • npx wrangler login/out --profile --dir - binds and unbinds a profile to a directory (defaults to cwd if --dir is not passed in). Login offers to create the profile if it does not exist, and logout offers to delete if nothing else is using the profile.
  • npx wrangler profiles create - creates without setting the profile
  • npx wrangler profiles delete - revoke token and unbind all directories
  • npx wrangler profiles list

Also adds the env var WRANGLER_PROFILE to override any directory bindings as a one off.

TODO in follow up:

  • make it show what accounts each token is associated with in the list command

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: TODO?

A picture of a cute animal (not mandatory, but encouraged)


Open in Devin Review

@changeset-bot

changeset-bot Bot commented May 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4ed9988

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Minor
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod workers-devprod requested review from a team and petebacondarwin and removed request for a team May 19, 2026 16:15
@workers-devprod

workers-devprod commented May 19, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/cloudchamber
  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/auth-profiles-support.md: [@cloudflare/wrangler]
  • packages/workers-utils/src/environment-variables/factory.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/artifacts.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/containers/registries.test.ts: [@cloudflare/cloudchamber @cloudflare/wrangler]
  • packages/wrangler/src/tests/index.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/logout.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/profile.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/user.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/vpc.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/core/register-yargs-command.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/core/types.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/auth-variables.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/commands.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/login-shared.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/profiles.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/user.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/whoami.ts: [@cloudflare/wrangler]

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 19, 2026
@github-actions

github-actions Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new

pkg-pr-new Bot commented May 19, 2026

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/create-cloudflare@13975

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/deploy-helpers@13975

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/kv-asset-handler@13975

miniflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/miniflare@13975

@cloudflare/pages-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-shared@13975

@cloudflare/unenv-preset

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/unenv-preset@13975

@cloudflare/vite-plugin

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vite-plugin@13975

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vitest-pool-workers@13975

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/workers-editor-shared@13975

@cloudflare/workers-utils

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/workers-utils@13975

wrangler

npm i https://pkg.pr.new/cloudflare/workers-sdk/wrangler@13975

commit: 4ed9988

@petebacondarwin

Copy link
Copy Markdown
Contributor

@emily-shen - looks like the Ci is not happy and there are some suggestions from Devin.

@petebacondarwin petebacondarwin marked this pull request as draft May 20, 2026 09:38
@petebacondarwin petebacondarwin removed request for a team and petebacondarwin May 20, 2026 09:38
@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team May 20, 2026 09:38
bimsonz added 7 commits May 20, 2026 11:24
Allow users to be logged into multiple Cloudflare accounts
simultaneously via named profiles stored as separate TOML files.

- Add `wrangler profile list|use|delete` subcommands
- Add `--profile` global flag and WRANGLER_PROFILE env var
- Support `wrangler login --profile <name>` to store credentials
- Namespace account cache per profile to prevent cross-contamination
- Display active profile in `wrangler whoami` output

Profile resolution priority:
  --profile flag > WRANGLER_PROFILE env > profiles.toml > "default"

Profiles stored under ~/.wrangler/config/profiles/<name>.toml.
Default profile path unchanged for full backward compatibility.

Refs: #8956, #11513
Unify login handler to a single code path so the profile success
message and metrics event fire regardless of --scopes usage.

Fix profileExists, deleteProfile, and listProfiles to use
environment-aware paths via getAuthConfigFilePath, so profiles
created in staging are correctly found, listed, and deleted.
Validate WRANGLER_PROFILE and profiles.toml active_profile with
validateProfileName() to prevent invalid profile names from being
used in auth config file path construction.

Also reinitialise auth tokens in clearProfileOverride() to keep
cached credentials in sync when the active profile changes.
deleteProfile() previously used getActiveProfile() to check whether the
deleted profile was active, but getActiveProfile() respects --profile
and WRANGLER_PROFILE overrides. This meant profiles.toml could be left
pointing at a deleted profile when a different override was active.

Extract getActiveProfileFromConfig() to read profiles.toml directly,
ignoring runtime overrides, and use it in deleteProfile().
- Add profile field to whoami --json test expectation
- Update inline snapshots for experimental-commands-api and functions-build
- Add WRANGLER_PROFILE to VariableNames type in workers-utils
- Fix "open-beta" -> "open beta" status enum in profile commands
- Use expect from test context in profile.test.ts (lint rule)
@emily-shen emily-shen force-pushed the emily/profiles branch 2 times, most recently from 28a3ff7 to 206d263 Compare May 20, 2026 16:36
@emily-shen emily-shen marked this pull request as ready for review May 21, 2026 08:52
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

import type { ExpectStatic } from "vitest";

describe("containers registries --help", () => {
runInTempDir();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have had to do this to a bunch of test files to make sure that running tests locally while you have a profile active doesn't contaminate the snapshots

@emily-shen emily-shen force-pushed the emily/profiles branch 2 times, most recently from 3fbaf9d to bef712f Compare May 21, 2026 10:04
devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View 21 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/user/commands.ts Outdated
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/cloudchamber
  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/auth-profiles-support.md: [@cloudflare/wrangler]
  • packages/workers-utils/src/environment-variables/factory.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/artifacts.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/containers/registries.test.ts: [@cloudflare/cloudchamber @cloudflare/wrangler]
  • packages/wrangler/src/tests/index.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/logout.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/profile.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/user.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/vpc.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/core/register-yargs-command.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/core/types.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/auth-variables.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/commands.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/login-shared.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/profiles.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/user.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/whoami.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@emily-shen

Copy link
Copy Markdown
Contributor Author

see #14200

@emily-shen emily-shen closed this Jun 8, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants