Skip to content

refactor(portal-framework-auth): simplify API URL handling and add localhost JWT storage#448

Merged
pcfreak30 merged 1 commit intodevelopfrom
libs/portal-framework-auth
Aug 14, 2025
Merged

refactor(portal-framework-auth): simplify API URL handling and add localhost JWT storage#448
pcfreak30 merged 1 commit intodevelopfrom
libs/portal-framework-auth

Conversation

@pcfreak30
Copy link
Copy Markdown
Member

@pcfreak30 pcfreak30 commented Aug 14, 2025

  • Remove redundant API URL configuration options in Capability class
  • Add local JWT storage for localhost development in auth provider
  • Ensure consistent API base URL usage across auth flows

Summary by CodeRabbit

  • New Features

    • After login on localhost, your session token is saved in the browser so you stay signed in across page reloads; signing out clears that stored token.
  • Bug Fixes

    • The app now resolves the API address using its default resolution rules, improving connectivity and behavior across development and subdomain setups.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 14, 2025

⚠️ No Changeset found

Latest commit: 018015b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 14, 2025

Walkthrough

SDK initialization now calls getApiBaseUrl with only currentUrl (removed allowLocalhost and preserveSubdomain options). The auth provider now conditionally persists the JWT to localStorage when the resolved API base URL hostname is "localhost" after login (both OTP and non-OTP paths) and removes it on logout; getApiBaseUrl was imported.

Changes

Cohort / File(s) Summary of Changes
SDK initialization URL resolution
libs/portal-framework-auth/src/capabilities/sdk.ts
Simplified getApiBaseUrl invocation to pass only currentUrl; removed allowLocalhost and preserveSubdomain options. Retained API-url validation, SDK construction, and existing error wrapping.
Auth token persistence & logout
libs/portal-framework-auth/src/dataProviders/auth.ts
Added getApiBaseUrl import. After login (OTP and non-OTP) and sdk.setAuthToken, resolves base URL and if hostname === "localhost", stores token in localStorage under "jwt" (URL parse errors ignored). On logout, resolves base URL and removes "jwt" from localStorage when hostname is "localhost". In-memory token handling unchanged.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant AuthProvider
  participant SDK
  participant Core as getApiBaseUrl
  participant Storage as localStorage

  User->>AuthProvider: login(credentials)  -- OTP or non-OTP path
  AuthProvider->>SDK: authenticate(...)
  SDK-->>AuthProvider: token
  AuthProvider->>SDK: setAuthToken(token)
  AuthProvider->>Core: getApiBaseUrl()
  Core-->>AuthProvider: baseUrl
  alt baseUrl.hostname == "localhost"
    AuthProvider->>Storage: setItem("jwt", token)
  end
  AuthProvider-->>User: login success
Loading
sequenceDiagram
  participant User
  participant AuthProvider
  participant Backend
  participant Core as getApiBaseUrl
  participant Storage as localStorage

  User->>AuthProvider: logout()
  AuthProvider->>Backend: POST /logout
  Backend-->>AuthProvider: success
  AuthProvider->>Core: getApiBaseUrl()
  Core-->>AuthProvider: baseUrl
  alt baseUrl.hostname == "localhost"
    AuthProvider->>Storage: removeItem("jwt")
  end
  AuthProvider-->>User: logout complete
Loading
sequenceDiagram
  participant App
  participant Capability
  participant Core as getApiBaseUrl
  participant SDK

  App->>Capability: initialize(currentUrl)
  Capability->>Core: getApiBaseUrl(currentUrl)
  Core-->>Capability: apiUrl | false
  alt apiUrl
    Capability->>SDK: new Sdk(apiUrl)
    SDK-->>Capability: instance
  else invalid
    Capability-->>App: throw "Invalid API URL configuration"
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble tokens in the devland plot,
A tiny rabbit guarding a localhost spot.
SDK trimmed flags, the path is neat,
JWT tucked where local devs meet.
Hop, hop—deploys dance to a smaller beat. 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a4608b and 018015b.

📒 Files selected for processing (2)
  • libs/portal-framework-auth/src/capabilities/sdk.ts (0 hunks)
  • libs/portal-framework-auth/src/dataProviders/auth.ts (4 hunks)
💤 Files with no reviewable changes (1)
  • libs/portal-framework-auth/src/capabilities/sdk.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/portal-framework-auth/src/dataProviders/auth.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch libs/portal-framework-auth

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
Copy Markdown

@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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d513ead and 5a4608b.

📒 Files selected for processing (2)
  • libs/portal-framework-auth/src/capabilities/sdk.ts (0 hunks)
  • libs/portal-framework-auth/src/dataProviders/auth.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • libs/portal-framework-auth/src/capabilities/sdk.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
libs/portal-framework-auth/src/dataProviders/auth.ts (1)
libs/portal-framework-core/src/index.ts (1)
  • getApiBaseUrl (58-58)
🔇 Additional comments (1)
libs/portal-framework-auth/src/dataProviders/auth.ts (1)

13-14: Import looks correct and aligns with intended usage

Bringing getApiBaseUrl into this module is appropriate for gating localhost-only persistence. The return type (string | undefined) matches how you guard its usage later.

…calhost JWT storage

- Remove redundant API URL configuration options in Capability class
- Add local JWT storage for localhost development in auth provider
- Ensure consistent API base URL usage across auth flows
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.

1 participant