Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

[MOC-218] handle login logout gracefully #162

Merged
merged 6 commits into from
Aug 27, 2024
Merged

[MOC-218] handle login logout gracefully #162

merged 6 commits into from
Aug 27, 2024

Conversation

fitzk
Copy link
Contributor

@fitzk fitzk commented Aug 26, 2024

Dependent PR: https://github.com/Mocksi/nest/pull/30

  • checks jwt expiration
  • nest PR adds component for reloading extension in case of an auth error

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Improved authentication handling to ensure actions are only taken when the user is logged in.
    • Enhanced TypeScript linting rules for better management of unused variables.
    • Added support for decoding JSON Web Tokens (JWT) with the new dependency.
  • Bug Fixes

    • Added robustness to authentication checks to prevent errors when keys are missing.
  • Style

    • Enhanced readability of conditional statements in the message listener logic.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Improved authentication handling to ensure actions are only taken when the user is logged in.
    • Enhanced TypeScript linting rules for better management of unused variables.
    • Added support for decoding JSON Web Tokens (JWT) with the new dependency.
  • Bug Fixes

    • Added robustness to authentication checks to prevent errors when keys are missing.
  • Style

    • Enhanced readability of conditional statements in the message listener logic.

@fitzk fitzk requested a review from jonathankap August 26, 2024 23:43
Copy link

linear bot commented Aug 26, 2024

Copy link

coderabbitai bot commented Aug 26, 2024

Walkthrough

Walkthrough

The changes include updates to ESLint configurations for improved TypeScript linting and modifications to the logic in several functions related to authentication handling and message listening in a Chrome extension. The configuration files were adjusted to introduce new rules and plugins, while the main logic files were updated to enhance error handling, control flow, and asynchronous behavior.

Changes

File Change Summary
.eslintrc.js, apps/mocksi-lite-next/.eslintrc ESLint configurations updated with new rules for unused variables and the @typescript-eslint plugin; ignorePatterns and root properties set.
apps/mocksi-lite-next/src/pages/background/index.ts Logic updates in getAuth and showAuthTab functions for better error handling and asynchronous behavior; event listener for chrome.action.onClicked made async.
apps/mocksi-lite-next/package.json Added jwt-decode dependency to handle JSON Web Tokens.
apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx Changed DOM element ID from "__root" to "__mocksi__root"; reformatted conditional statements for readability without altering functionality.

Poem

🐰 In the code where rabbits hop,
Changes made, we shall not stop!
With linting rules, our paths are clear,
Asynchronous hops bring joy and cheer!
In every function, a new dance unfolds,
With each small change, a story told! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fitzk fitzk changed the title [Moc-218] handle login logout gracefully [MOC-218] handle login logout gracefully Aug 26, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66a67e6 and d91b3da.

Files selected for processing (4)
  • .eslintrc.js (1 hunks)
  • apps/mocksi-lite-next/.eslintrc (1 hunks)
  • apps/mocksi-lite-next/src/pages/background/index.ts (3 hunks)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx
Additional context used
Biome
apps/mocksi-lite-next/src/pages/background/index.ts

[error] 38-61: Promise executor functions should not be async.

(lint/suspicious/noAsyncPromiseExecutor)

Additional comments not posted (9)
.eslintrc.js (4)

5-5: LGTM!

The addition of ignorePatterns is correct and follows best practices.


10-10: LGTM!

The addition of the @typescript-eslint plugin enhances TypeScript linting capabilities.


11-11: LGTM!

Setting root to true is correct and indicates that this configuration is the root of the ESLint configuration hierarchy.


12-15: LGTM!

The addition of these rules is correct and prevents conflicts between the @typescript-eslint/no-unused-vars and no-unused-vars rules.

apps/mocksi-lite-next/.eslintrc (2)

26-26: LGTM!

Turning off the no-unused-vars rule prevents conflicts with the @typescript-eslint/no-unused-vars rule.


27-32: LGTM!

The addition of the @typescript-eslint/no-unused-vars rule is correct and allows for more flexible handling of unused variables in function parameters.

apps/mocksi-lite-next/src/pages/background/index.ts (3)

10-11: LGTM!

The changes enhance the function's robustness against missing authentication data and ensure consistent return values.

Also applies to: 18-18


72-79: LGTM!

The changes improve the user experience by ensuring that actions are only taken when the necessary credentials are available.


Line range hint 1-79: Overall LGTM!

The overall implementation appears to be correct and aligns with best practices.

apps/mocksi-lite-next/src/pages/background/index.ts Outdated Show resolved Hide resolved
@fitzk fitzk requested a review from elg0nz August 27, 2024 00:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d91b3da and 23e0ca6.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/background/index.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/mocksi-lite-next/src/pages/background/index.ts

if (loadUrl.href === tabUrl.href) {
tabExists = true;
break;
if (auth?.accessToken) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if not authenticated, open a new tab for auth, even if there is one open already

if (tab.id) {
chrome.tabs.sendMessage(tab.id, { message: "mount-extension" });
const auth = await getAuth();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

checks auth on toolbar icon click

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 23e0ca6 and 3ce79ff.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (3)
  • apps/mocksi-lite-next/package.json (1 hunks)
  • apps/mocksi-lite-next/src/pages/background/index.ts (7 hunks)
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apps/mocksi-lite-next/src/pages/background/index.ts
  • apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx
Additional comments not posted (1)
apps/mocksi-lite-next/package.json (1)

4-4: Approved: Addition of jwt-decode dependency.

The addition of jwt-decode with version ^4.0.0 is appropriate for handling JWTs, which aligns with the PR objectives to enhance login/logout handling.

The code changes are approved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3ce79ff and 0ff6152.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/background/index.ts (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/mocksi-lite-next/src/pages/background/index.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0ff6152 and 5b98e62.

Files selected for processing (1)
  • apps/mocksi-lite-next/src/pages/background/index.ts (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/mocksi-lite-next/src/pages/background/index.ts

Copy link
Contributor

@jonathankap jonathankap left a comment

Choose a reason for hiding this comment

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

Looks good

@fitzk fitzk merged commit fd38a37 into main Aug 27, 2024
3 checks passed
@fitzk fitzk deleted the MOC-218_login-logout branch August 27, 2024 17:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants