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/api): more descriptive api errors & CLI warning when using token auth while being logged in #2445

Merged
merged 9 commits into from
Sep 19, 2024

Conversation

DanielHougaard
Copy link
Contributor

@DanielHougaard DanielHougaard commented Sep 17, 2024

Description 📣

API:

This PR adds more descriptive error messages for certain errors. Specifically we are now formatting JWT-related errors, so they're more understandable for the end users.

CLI:

We are now checking if the user is using user-based auth, and token based auth at the same time. If the user is using both token-based and user-based authentication, we will display a warning letting the user know that the token-based auth is being used.

This has been confusing users in the past, so this aims to add more clarity which authentication method is being used.

After talking to @maidul98, this seemed like something we'd want to keep on the API-end, instead handling directly in the CLI codebase.

Type ✨

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

@DanielHougaard DanielHougaard self-assigned this Sep 17, 2024
@DanielHougaard DanielHougaard requested review from akhilmhdh and maidul98 and removed request for akhilmhdh September 17, 2024 19:46
Copy link
Collaborator

@maidul98 maidul98 left a comment

Choose a reason for hiding this comment

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

Let's remove the errors specific to CLI and keeps the generic ones

backend/src/server/plugins/error-handler.ts Outdated Show resolved Hide resolved
backend/src/server/plugins/error-handler.ts Outdated Show resolved Hide resolved
backend/src/server/plugins/error-handler.ts Outdated Show resolved Hide resolved
backend/src/server/plugins/error-handler.ts Outdated Show resolved Hide resolved
@DanielHougaard DanielHougaard changed the title fix(api): more descriptive api errors feat(cli/api): more descriptive api errors & CLI warning when using token auth while being logged in Sep 17, 2024
Copy link
Collaborator

@maidul98 maidul98 left a comment

Choose a reason for hiding this comment

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

Backend changes look good but for CLI, a better approach is to make use of PersistentPreRun function in the root CMD. You can call a function there and it will get run by every child command.

What we want to check for is if there is a token over ride either from --token flag or from environment. If we see them being set we can show the message. Here is a example

CleanShot 2024-09-17 at 21 44 05@2x CleanShot 2024-09-17 at 21 44 55@2x

Copy link
Collaborator

@maidul98 maidul98 left a comment

Choose a reason for hiding this comment

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

Made minor adjustment to the error warning message and removed the comments. Let’s only add comments for very nuanced logic

cli/packages/models/cli.go Outdated Show resolved Hide resolved
cli/packages/cmd/root.go Outdated Show resolved Hide resolved
cli/packages/cmd/run.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@maidul98 maidul98 left a comment

Choose a reason for hiding this comment

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

source would be better set as a enum of sorts because now the get token function is tightly coupled with the warning logic but this is fine for now

@DanielHougaard DanielHougaard merged commit 8ace72d into main Sep 19, 2024
5 checks passed
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