Skip to content

Conversation

@gavande1
Copy link
Contributor

@gavande1 gavande1 commented May 9, 2025

Related issues

Proposed Changes

This PR addresses the issue of invalid authentication states in Studio. Currently, the CLI uses the access token without first checking if it's still valid or has been revoked. To fix this, the PR adds a step to validate the access token by calling the /me endpoint before starting any CLI process.

Testing Instructions

  1. Check out this branch.

  2. Start the app:

    npm start  
  3. Log in to your WordPress.com account.

  4. Build the CLI:

    npm run cli:build  
  5. Run the following command to create or list preview sites:

    node dist/cli/main.js preview list --path ~/Studio/[SITE_NAME]  
  6. Confirm that it lists existing preview sites. If none exist, create one.

  7. Open your appdata-v1.json file, located at: "/Users/[YOUR_USER]/Library/Application Support/Studio/appdata-v1.json"

  8. Manually modify the authToken.accessToken value to an invalid token.

  9. Run the same CLI command again:

    node dist/cli/main.js preview list --path ~/Studio/[SITE_NAME]  
  10. The CLI should now return an authentication required message.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@gavande1 gavande1 requested a review from a team May 9, 2025 12:19
@gavande1 gavande1 self-assigned this May 9, 2025
@gavande1 gavande1 changed the title Stu 464 studio cli doesnt check authentication state on windows Studio CLI: Validate access token before starting command operation May 9, 2025
Copy link
Contributor

@epeicher epeicher left a comment

Choose a reason for hiding this comment

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

Thanks Rahul! I have tested this, and it works as expected. When modifying the token, the CLI returns the error as expected. LGTM!

CleanShot 2025-05-09 at 16 46 46@2x

@fredrikekelund
Copy link
Contributor

Nice improvement 👍

@gavande1 gavande1 merged commit 5a1df1f into trunk May 12, 2025
10 checks passed
@gavande1 gavande1 deleted the stu-464-studio-cli-doesnt-check-authentication-state-on-windows branch May 12, 2025 09:29
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.

4 participants