Skip to content

feat(cli/api): more descriptive api errors & CLI warning when using token auth while being logged in#2445

Merged
varonix0 merged 9 commits intomainfrom
daniel/better-api-errors
Sep 19, 2024
Merged

feat(cli/api): more descriptive api errors & CLI warning when using token auth while being logged in#2445
varonix0 merged 9 commits intomainfrom
daniel/better-api-errors

Conversation

@varonix0
Copy link
Copy Markdown
Member

@varonix0 varonix0 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

@varonix0 varonix0 self-assigned this Sep 17, 2024
@varonix0 varonix0 requested review from akhilmhdh and maidul98 and removed request for akhilmhdh September 17, 2024 19:46
Copy link
Copy Markdown
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

Comment thread backend/src/server/plugins/error-handler.ts Outdated
Comment thread backend/src/server/plugins/error-handler.ts Outdated
Comment thread backend/src/server/plugins/error-handler.ts Outdated
Comment thread backend/src/server/plugins/error-handler.ts Outdated
@varonix0 varonix0 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
@varonix0 varonix0 requested a review from maidul98 September 17, 2024 21:47
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread cli/packages/models/cli.go Outdated
Comment thread cli/packages/cmd/root.go Outdated
Comment thread cli/packages/cmd/run.go Outdated
@varonix0 varonix0 requested a review from maidul98 September 18, 2024 16:44
Copy link
Copy Markdown
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

@varonix0 varonix0 merged commit 8ace72d into main Sep 19, 2024
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