Skip to content
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

feat(cli): reauthenticate user in case of invalid token #3643

Merged
merged 6 commits into from
Feb 16, 2024
Merged

Conversation

schoren
Copy link
Contributor

@schoren schoren commented Feb 15, 2024

This PR improves the error handling when the server does not accept the JWT token for whatever reason (corrupted config file, expired token, anything that makes the server return a 401 code).
When an auth error happens, the authentication flow begins, and the issued command is automatically rerun with the new credentials.

For the case of the start cmd, this new behaviour was causing the cli to show 2 times the org/env selector: once for the new auth and another one for the start command (it shows the selector when started unless org/env are passed via flags).
To overcome this issue, I added some context magic to pass the values around in a relatively seamless way so this command can pick the values and not ask the user 2 times.

Changes

Fixes

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

Loom video

https://www.loom.com/share/cf956f7d668f475baa22678d4ac6a7bf

Copy link

vercel bot commented Feb 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tracetest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 15, 2024 10:44pm

@schoren schoren linked an issue Feb 15, 2024 that may be closed by this pull request
Copy link
Contributor

@xoscar xoscar left a comment

Choose a reason for hiding this comment

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

The code looks good, I'd suggest @kdhamric taking a look at the video to see if it matches what he wants

flags.EnvironmentID = envID
}

spew.Dump(flags)
Copy link
Contributor

Choose a reason for hiding this comment

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

spew 🔫

}

func handleAuthError(ctx context.Context) {
ui.DefaultUI.Warning("Your authentication token has expired, please log in again.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this handles environment tokens expiration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. I didn't test that case, but this mechanism is triggered whenever the server returns a 401. So if an expired token throws a 401, then this will be triggered.

@schoren schoren merged commit 1b4865a into main Feb 16, 2024
39 checks passed
@schoren schoren deleted the cli-update-jwt branch February 16, 2024 14:51
@kdhamric
Copy link
Collaborator

I watched the video - looks awesome @schoren !

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.

JWT Token expired
4 participants