Skip to content

Studio CLI: Validate access token before starting command operation - #1364

Merged
gavande1 merged 2 commits into
trunkfrom
stu-464-studio-cli-doesnt-check-authentication-state-on-windows
May 12, 2025
Merged

Studio CLI: Validate access token before starting command operation#1364
gavande1 merged 2 commits into
trunkfrom
stu-464-studio-cli-doesnt-check-authentication-state-on-windows

Conversation

@gavande1

@gavande1 gavande1 commented May 9, 2025

Copy link
Copy Markdown
Contributor

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 May 9, 2025

@epeicher epeicher 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.

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
Copy Markdown
Contributor

Nice improvement 👍

@gavande1
gavande1 merged commit 5a1df1f into trunk May 12, 2025
@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

3 participants