Skip to content

feat: log in again when a command finds no valid login - #446

Draft
angeloashmore wants to merge 3 commits into
claude/single-prismic-clientfrom
claude/reauth-on-auth-error
Draft

angeloashmore wants to merge 3 commits into
claude/single-prismic-clientfrom
claude/reauth-on-auth-error

Conversation

@angeloashmore

@angeloashmore angeloashmore commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Resolves: #443

Description

Before this PR, a command stopped with an error when the login was missing or expired. The developer had to run prismic login and then run the command again. An agent had to read the error and do the same steps. Only prismic init started a login on its own.

After this PR, the command prints a login URL, waits for the login, and continues from where it stopped. It does not open a browser, so the same flow works for a developer and for an agent that passes the URL on. All commands that use the Prismic API work this way.

prismic login and prismic init still open the browser, unless --no-browser is set. The CLI does not start a login when PRISMIC_TOKEN is set or in CI. A user without access to a repository still gets the access error. prismic whoami still only reports the login state.

This PR is stacked on #445.

Checklist

  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

$ prismic repo list
Your login expired.
Open this URL to log in: https://prismic.io/dashboard/cli/login?source=prismic-cli&port=5555
Logged in to Prismic as dev@example.com
DOMAIN     NAME       ROLE
my-repo    My Repo    Owner

When no login is stored, the first line is You are not logged in.

How to QA 1

  1. Run prismic logout.
  2. Run prismic repo list.
  3. Open the printed URL and log in to Prismic. The command then lists your repositories.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L1dGD6G4hXCqeewEhox2Du

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment. ↩

@angeloashmore
angeloashmore force-pushed the claude/reauth-on-auth-error branch 3 times, most recently from 6f3d679 to ac95676 Compare October 29, 2026 22:03
A command stopped with a login error when the login was missing or
expired. The developer had to run `prismic login` and the command again.

Now the request that fails starts a login, waits for it, and retries
with the new token. The command then continues. Parallel requests share
one login, and later requests use the new token.

- request takes an onAuthError handler for 401 and 403 errors.
- Each client function that sends a token retries itself once with the
  token that the handler returns. The client does not know about the
  login.
- getCredentials gives the handler. It does not log in when
  PRISMIC_TOKEN or CI is set.
- Most services answer an expired login with a 403. On a 403, the
  handler checks the token first, so a user without access gets the
  usual error.
- whoami and telemetry never start a login.
- init and login share the new logIn function.
- A login timeout is now a known error, not a reported bug.

Closes #443

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L1dGD6G4hXCqeewEhox2Du
@angeloashmore
angeloashmore force-pushed the claude/reauth-on-auth-error branch from ac95676 to e50c54a Compare October 29, 2026 22:07
A login that starts in the middle of a command now prints its URL and
does not open a browser. prismic init and prismic login still open the
browser unless --no-browser is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L1dGD6G4hXCqeewEhox2Du
getCredentials returns the host and a getToken function. A client
request asks getToken for the token. When the token is missing or
invalid, the request asks getToken({ login: true }) for a new one, which
starts the login. Later requests then get the new token.

The client now decides which errors mean an invalid token. getCredentials
only gives tokens. Commands pass host and getToken explicitly.

whoami, telemetry, and the error messages use allowLogin: false, so they
never start a login. init logs in with the browser before it changes the
project, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L1dGD6G4hXCqeewEhox2Du
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants