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: new auth manager uncomplicated #558

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

Kodylow
Copy link
Member

@Kodylow Kodylow commented Oct 10, 2024

Okay entire new auth context was getting overly complicated and there's some pretty serious crypto concerns, so made this far simpler one that just uses the browser's password manager, saving passwords per service in the password manager and only ever holding in session storage after you've logged in for the session.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new id property for session management in Gateway and Guardian APIs.
    • Added a setSessionPassword method in the Guardian API for improved password handling.
    • Enhanced the Login component with a serviceId prop for better accessibility.
  • Bug Fixes

    • Removed unnecessary complexity from the Connect Service Modal by eliminating the password state.
  • Refactor

    • Streamlined context usage in hooks for Guardian and Gateway.
    • Enhanced service identification process in the App Context.
  • Type Updates

    • Updated GatewayConfig and GuardianConfig types to include an id property.

@Kodylow Kodylow requested review from a team as code owners October 10, 2024 23:51
Copy link

vercel bot commented Oct 10, 2024

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

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 11:56pm

@Kodylow
Copy link
Member Author

Kodylow commented Oct 10, 2024

This'll also work nicely for when we move the guardians and gateways to the JWT based schemes so we just keep those in session storage instead of the passwords

Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces significant changes across multiple files, primarily focusing on the management of session storage and service configurations. The GatewayApi and GuardianApi classes have been updated to replace a constant session storage key with an instance-specific id property. The ServiceCheckApi class has been removed, and various context and hook files have been refactored to streamline service handling. Additionally, new properties have been added to the GatewayConfig and GuardianConfig types, enhancing the structure of service configurations.

Changes

File Path Change Summary
apps/router/src/api/GatewayApi.ts Added private property id, removed SESSION_STORAGE_KEY, updated methods to use this.id.
apps/router/src/api/GuardianApi.ts Removed SESSION_STORAGE_KEY, added setSessionPassword method, updated password handling.
apps/router/src/api/ServiceCheckApi.ts Class and interface removed.
apps/router/src/context/AppContext.tsx Updated addService to create newService with hashed baseUrl.
apps/router/src/context/guardian/SetupContext.tsx Replaced useGuardianApi with useGuardianContext.
apps/router/src/context/hooks.tsx Consolidated hooks to use useGuardianContext and useGatewayContext.
apps/router/src/guardian-ui/Guardian.tsx Added id to useGuardianContext destructured return.
apps/router/src/gateway-ui/Gateway.tsx Added id to useGatewayContext destructured return.
packages/ui/src/Login.tsx Added serviceId to LoginProps, updated input attributes for accessibility.
apps/router/src/types/gateway.tsx Added id property to GatewayConfig.
apps/router/src/types/guardian.tsx Added id property to GuardianConfig.

Possibly related PRs

Suggested reviewers

  • tvolk131

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 80e260f and c316f62.

📒 Files selected for processing (5)
  • apps/router/src/api/GatewayApi.ts (3 hunks)
  • apps/router/src/context/AppContext.tsx (1 hunks)
  • apps/router/src/gateway-ui/Gateway.tsx (2 hunks)
  • apps/router/src/guardian-ui/Guardian.tsx (3 hunks)
  • packages/ui/src/Login.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/router/src/context/AppContext.tsx
🧰 Additional context used
📓 Learnings (1)
apps/router/src/guardian-ui/Guardian.tsx (1)
Learnt from: Kodylow
PR: fedimint/ui#547
File: apps/router/src/context/hooks.tsx:69-69
Timestamp: 2024-10-10T21:30:04.372Z
Learning: In `apps/router/src/context/hooks.tsx`, the function `useGuardianConfig` returns an object with `id` and `config` properties, and its return type matches the interface accordingly.
🔇 Additional comments (12)
apps/router/src/guardian-ui/Guardian.tsx (2)

14-14: Approved: Addition of id property.

The id property is correctly destructured from the useGuardianContext hook.


40-40: Approved: Proper usage of id property.

The id is correctly used as serviceId in the Login component and added to the useMemo dependency array.

Also applies to: 82-82

packages/ui/src/Login.tsx (5)

18-18: Addition of serviceId to LoginProps interface is appropriate.


25-25: Updated component signature correctly includes serviceId.


68-70: FormLabel now correctly links to the input, improving accessibility.


73-74: Input component now has proper id and name attributes, enhancing accessibility and form handling.


79-79: Addition of autoComplete='current-password' improves security and user experience.

apps/router/src/gateway-ui/Gateway.tsx (1)

20-20: Changes look good.

The addition of id to the context and its usage in the Login component aligns with the PR objectives.

Also applies to: 33-33

apps/router/src/api/GatewayApi.ts (4)

22-22: LGTM: Addition of id property

The new id property allows for instance-specific identifiers, which is beneficial for managing multiple gateway instances.


26-26: LGTM: Initialization of id property

The id property is correctly initialized in the constructor, ensuring each GatewayApi instance has a unique identifier.


38-38: LGTM: Use of instance-specific id in testPassword

The use of this.id for session storage allows for instance-specific keys, which is an improvement over a global constant.


52-52: LGTM: Consistent use of instance-specific id

The getPassword and clearPassword methods now correctly use the instance-specific this.id, maintaining consistency with the other changes.

Also applies to: 56-56


🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link
Contributor

@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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c609b2e and 80e260f.

📒 Files selected for processing (11)
  • apps/router/src/api/GatewayApi.ts (3 hunks)
  • apps/router/src/api/GuardianApi.ts (5 hunks)
  • apps/router/src/api/ServiceCheckApi.ts (0 hunks)
  • apps/router/src/context/AppContext.tsx (1 hunks)
  • apps/router/src/context/guardian/SetupContext.tsx (2 hunks)
  • apps/router/src/context/hooks.tsx (3 hunks)
  • apps/router/src/guardian-ui/utils/env.ts (1 hunks)
  • apps/router/src/home/ConnectServiceModal.tsx (4 hunks)
  • apps/router/src/types/gateway.tsx (1 hunks)
  • apps/router/src/types/guardian.tsx (1 hunks)
  • packages/ui/src/KeyValues.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/router/src/api/ServiceCheckApi.ts
🧰 Additional context used
📓 Learnings (3)
apps/router/src/api/GuardianApi.ts (1)
Learnt from: Kodylow
PR: fedimint/ui#547
File: apps/router/src/api/GuardianApi.ts:29-35
Timestamp: 2024-10-10T21:21:37.491Z
Learning: In the TypeScript file `apps/router/src/api/GuardianApi.ts`, temporary storage of the password as a class property in `GuardianApi` is acceptable during refactoring towards browser-native password management handled by the Auth Manager.
apps/router/src/context/guardian/SetupContext.tsx (3)
Learnt from: Kodylow
PR: fedimint/ui#547
File: apps/router/src/context/guardian/SetupContext.tsx:71-71
Timestamp: 2024-10-10T20:23:07.421Z
Learning: In `apps/router/src/context/guardian/SetupContext.tsx`, the `SET_INITIAL_STATE` action in the reducer returns the current state without modification because handling is performed in the provider.
Learnt from: Kodylow
PR: fedimint/ui#547
File: apps/router/src/context/guardian/SetupContext.tsx:135-137
Timestamp: 2024-09-27T21:39:41.672Z
Learning: In this codebase, the context is only loaded while in `guardian/id`, so `guardianId` will always be defined, and validation for `guardianId` being undefined is unnecessary.
Learnt from: Kodylow
PR: fedimint/ui#547
File: apps/router/src/context/hooks.tsx:51-54
Timestamp: 2024-10-10T21:28:22.154Z
Learning: The function `useAppGuardianConfigs` is unused and has been removed.
apps/router/src/context/hooks.tsx (2)
Learnt from: Kodylow
PR: fedimint/ui#547
File: apps/router/src/context/hooks.tsx:51-54
Timestamp: 2024-10-10T21:28:22.154Z
Learning: The function `useAppGuardianConfigs` is unused and has been removed.
Learnt from: Kodylow
PR: fedimint/ui#547
File: apps/router/src/context/hooks.tsx:69-69
Timestamp: 2024-10-10T21:30:04.372Z
Learning: In `apps/router/src/context/hooks.tsx`, the function `useGuardianConfig` returns an object with `id` and `config` properties, and its return type matches the interface accordingly.
🔇 Additional comments (9)
apps/router/src/types/gateway.tsx (1)

5-7: Approve addition of id to GatewayConfig.

The new id property in GatewayConfig aligns with the PR objectives. Ensure all GatewayConfig usages are updated.

apps/router/src/types/guardian.tsx (1)

4-5: Addition of id property enhances guardian identification.

The new id property in GuardianConfig allows for unique identification of guardians, which can improve management and security.

apps/router/src/context/guardian/SetupContext.tsx (1)

14-14: Approved: New import aligns with simplification goals.

apps/router/src/home/ConnectServiceModal.tsx (1)

112-116: Error handling inconsistency with Enter key press.

The handleConfirm function is called directly on Enter key press, bypassing the error state reset that occurs in the onClick handler of the confirm button. This could lead to stale error messages.

apps/router/src/context/AppContext.tsx (1)

188-198: Changes look good.

The addition of the id property and the use of newService in checks and payloads improve service identification and consistency.

apps/router/src/api/GuardianApi.ts (1)

310-310: Potential security issue with null authentication

Using null for authentication when no password is available might lead to unintended authentication behavior. Consider using an empty string or omitting the auth field entirely when no password is present.

apps/router/src/context/hooks.tsx (3)

Line range hint 84-134: Potential performance issue with dependency array

Including id in the useEffect dependency array might cause unnecessary re-renders if id changes frequently.


442-445: Potential security risk with session storage

Setting state.needsAuth to false based on the presence of id in sessionStorage might introduce a security vulnerability if not properly managed.


Line range hint 447-502: Potential performance issue with dependency array

Including api and dispatch in the useEffect dependency array might cause unnecessary re-renders if these values change frequently.

apps/router/src/guardian-ui/utils/env.ts Show resolved Hide resolved
packages/ui/src/KeyValues.tsx Show resolved Hide resolved
apps/router/src/api/GatewayApi.ts Outdated Show resolved Hide resolved
@Kodylow Kodylow changed the title feat: new auth context uncomplicated feat: new auth manager uncomplicated Oct 10, 2024
@Kodylow Kodylow merged commit 4db0a91 into fedimint:master Oct 15, 2024
3 checks passed
@Kodylow Kodylow deleted the new-auth-manager branch October 15, 2024 02:56
This was referenced Oct 22, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 9, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 20, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 23, 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