Skip to content

feat: automatic cloudflare login #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

Conversation

john-royal
Copy link
Collaborator

@john-royal john-royal commented Jun 24, 2025

Automatically logs in with Cloudflare when Wrangler config is unavailable or if the token refresh fails. Should help with #438.

  • This does introduce a new dependency, open — this is because opening the URL cross-platform gets messy fast. I tried a simpler in-house method but seemed to completely butcher the URL. Happy to look at this further if we want to avoid the dependency.
  • Auto-login is disabled when CI is detected or if the terminal seems to be non-interactive.
  • Right now this is built into the current Cloudflare client setup, but we might want to make this part of the alchemy create CLI.

Idea: It would be really cool if we marked API requests as requiring specific scopes so we can start the reauthorization flow automatically if we hit an auth error.

Copy link

pkg-pr-new bot commented Jun 24, 2025

Open in StackBlitz

npm i https://pkg.pr.new/sam-goodwin/alchemy@475

commit: 96f1a5f

Copy link

🚀 Website Preview Deployed

Your website preview is ready!

Preview URL:

This preview was built from commit de8f66b


🤖 This comment will be updated automatically when you push new commits to this PR.

@sam-goodwin
Copy link
Owner

@claude please add a new command in alchemy/bin for alchemy login that:

  1. opens the same login flow to cloudflare like this PR does
  2. allows overriding the scopes via a CLI argument

Copy link
Contributor

claude bot commented Jun 26, 2025

Claude finished @sam-goodwin's task —— View job


I've successfully added the alchemy login command that reuses the login flow from this PR!

Tasks:

  • Read repository guidelines and understand existing CLI structure
  • Analyze the current login flow implementation
  • Extract reusable login logic
  • Create new CLI command with scope override support
  • Test the implementation
  • Run linting and formatting
  • Commit changes

Implementation Complete!

I've successfully added the alchemy login command with the following features:

  1. Reusable Login Function: Created loginToCloudflare() in auth.ts that accepts custom scopes
  2. CLI Command: Added login command to the CLI router with scope override support
  3. User Experience: Clean command interface with progress messages and scope listings

Usage:

# Login with default scopes (all available)
alchemy login

# Login with custom scopes
alchemy login --scopes="account:read,user:read,workers:write"

The implementation:

  • ✅ Passes biome linting and formatting
  • ✅ Builds successfully with TypeScript
  • ✅ Follows repository conventions
  • ✅ Handles interactive terminal detection
  • ✅ Provides clear error messages

Committed as: adf84ef - All changes have been added to this PR branch.

Add new `alchemy login` command that reuses the OAuth login flow from this PR:

- Export `DefaultScopes` and add `loginToCloudflare()` function in auth.ts
- Support custom scope override in OAuth authorize method
- Add login command handler with user-friendly prompts
- Integrate login command into main CLI router with scope CLI argument support

Usage:
- `alchemy login` (uses default scopes)
- `alchemy login --scopes="account:read,user:read"` (custom scopes)

Co-authored-by: sam <[email protected]>
@sam-goodwin sam-goodwin moved this to In Progress in alchemy Jul 4, 2025
@sam-goodwin sam-goodwin removed the status in alchemy Jul 4, 2025
@sam-goodwin sam-goodwin moved this to In Progress in alchemy Jul 4, 2025
Copy link

github-actions bot commented Jul 8, 2025

🚀 Website Preview Deployed

Your website preview is ready!

Preview URL: https://9f7588d3-alchemy-website.alchemy-run.workers.dev

This preview was built from commit d6d05d6


🤖 This comment will be updated automatically when you push new commits to this PR.

@john-royal
Copy link
Collaborator Author

Replaced by #631

@john-royal john-royal closed this Jul 10, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in alchemy Jul 10, 2025
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.

2 participants