Multiple Account Publishing Issues with Cloudflare Pages

Implementing multi-account publishing with Cloudflare Pages

Implementing multi-account publishing with Cloudflare Pages

2025-4-18

cloud flare pagewranglerwrangler pages deploy

Problem Description

Cloudflare uses wrangler for local publishing and login. How can we switch between multiple accounts?

Wrangler Publishing Methods

  1. oAuth browser authorization login publishing
  2. CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID
  • The oAuth publishing method uses your local account login, requiring browser authorization to proceed with the publishing action.
  wrangler login

This will launch a browser window, guiding you through the OAuth login process for Cloudflare.

  • For CLOUDFLARE_API_TOKEN publishing, you only need to create a new .env file locally
  CLOUDFLARE_API_TOKEN=""
  CLOUDFLARE_ACCOUNT_ID=""

Important Notes

  • When using CLOUDFLARE_API_TOKEN for local publishing for the first time, you might encounter: (πŸ‘‹ You are logged in with an API Token. Unable to retrieve email for this user. Are you missing the User->User Details->Read permission?) This can be resolved by using local wrangler login authorization.

Problem Description

How to handle multi-branch publishing with Cloudflare Pages?

Solution

  1. Use the following commands
wrangler pages deploy --branch=main // deploy to main branch
wrangler pages deploy --branch=develop // deploy to development branch

Important Notes

  • When initializing the project, pay attention to specifying the main branch name correctly the first time. This cannot be changed later, and you would need to delete and recreate the project if it's wrong.