Skip to content

Migrate sample app to use login widget 2.0 - #123

Merged
vatsalparikh merged 10 commits into
mainfrom
migrate-login-widget-2.0
Jul 27, 2026
Merged

Migrate sample app to use login widget 2.0#123
vatsalparikh merged 10 commits into
mainfrom
migrate-login-widget-2.0

Conversation

@vatsalparikh

@vatsalparikh vatsalparikh commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

DO NOT MERGE: Pending Login Widget 2.0 release. Dependencies need to be updated to latest.

Explanation

Below are the changes needed after login widget's 2.0 release, mostly config changes

  1. Journey client config
  2. OIDC client config
  3. Remove request API from sample apps and replace with fetch
  4. Update READMEs because we install from root of the repo instead of /javascript folder now

Summary by CodeRabbit

  • New Features

    • Added WELLKNOWN_URL configuration for the login widget.
    • Login journey can be selected via a URL query parameter (with fallback).
    • Protected API calls now use an explicit Authorization: Bearer … access token.
  • Bug Fixes

    • Improved authentication state hydration by reading tokens directly from the token store.
  • Documentation

    • Updated setup/run instructions to execute npm commands from the sdk-sample-apps repo root.
    • Added WELLKNOWN_URL to the login widget .env.example.
  • Chores

    • Updated the login widget dependency, build-time config, Playwright config, and CI node_modules caching.

@vatsalparikh vatsalparikh added the do not merge Do not merge label Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The Login Widget sample now uses WELLKNOWN_URL for OIDC and Journey configuration, retrieves bearer tokens for API requests, updates authentication-state handling, changes its dependency version, caches workspace dependencies in CI, and documents npm commands from the repository root.

Changes

Login Widget OIDC migration

Layer / File(s) Summary
Well-known endpoint configuration
javascript/reactjs-todo-login-widget/.env.example, client/constants.js, webpack.config.js, playwright.config.ts, package.json, client/index.js
Adds and injects WELLKNOWN_URL, configures OIDC/Journey clients with the well-known endpoint, and updates the Login Widget dependency.
Widget lifecycle and authentication state
javascript/reactjs-todo-login-widget/client/hooks/useLoginWidget.js, client/context/auth.context.js
Starts the selected or default journey and initializes authentication from token-store state.
Explicit token-based API requests
javascript/reactjs-todo-login-widget/client/utilities/request.js
Retrieves and validates an access token before sending API requests with bearer authorization.
Workspace-root setup and CI caching
javascript/reactjs-todo-*/README.md, .github/workflows/CI.yml
Updates npm commands to use the repository root and caches package-level node_modules directories in CI.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant useLoginWidget
  participant LoginWidget
  participant user.tokens
  participant ProtectedAPI
  Browser->>useLoginWidget: Call openModal()
  useLoginWidget->>LoginWidget: Start selected or default journey
  useLoginWidget->>user.tokens: Retrieve access token
  user.tokens-->>useLoginWidget: Return accessToken
  useLoginWidget->>ProtectedAPI: Fetch with Bearer authorization
Loading

Possibly related PRs

Suggested labels: do not merge

Suggested reviewers: cerebrl

Poem

I’m a rabbit with tokens tucked neat,
Well-known URLs make configs complete.
Journeys hop with a name to repeat,
Bearer fetches make APIs meet.
From workspace root, commands now leap.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: migrating the sample app to Login Widget 2.0.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch migrate-login-widget-2.0

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

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

@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch from 93e33fb to 9871bab Compare July 17, 2026 17:13
@vatsalparikh vatsalparikh changed the title Migrate login widget 2.0 Migrate sample app to use login widget 2.0 Jul 17, 2026
@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch 3 times, most recently from 2fe709c to 7a74a8a Compare July 17, 2026 19:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@javascript/reactjs-todo-login-widget/client/utilities/request.js`:
- Around line 34-38: Update the token retrieval flow around tokenEvents.get() to
inspect and handle the returned error before destructuring or accessing
response. Preserve the actual token retrieval failure when present, and only
fall back to the generic “Failed to retrieve access token” error when no error
exists but accessToken is missing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 95649044-f27c-41df-be47-0287c5e3e780

📥 Commits

Reviewing files that changed from the base of the PR and between f46e25f and 7a74a8a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (12)
  • javascript/reactjs-todo-davinci/README.md
  • javascript/reactjs-todo-journey/README.md
  • javascript/reactjs-todo-login-widget/.env.example
  • javascript/reactjs-todo-login-widget/README.md
  • javascript/reactjs-todo-login-widget/client/constants.js
  • javascript/reactjs-todo-login-widget/client/hooks/useLoginWidget.js
  • javascript/reactjs-todo-login-widget/client/index.js
  • javascript/reactjs-todo-login-widget/client/utilities/request.js
  • javascript/reactjs-todo-login-widget/package.json
  • javascript/reactjs-todo-login-widget/playwright.config.ts
  • javascript/reactjs-todo-login-widget/webpack.config.js
  • javascript/reactjs-todo-oidc/README.md

Comment thread javascript/reactjs-todo-login-widget/client/utilities/request.js Outdated
@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch from 7a74a8a to e8d8d15 Compare July 18, 2026 00:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
javascript/reactjs-todo-login-widget/client/utilities/request.js (1)

34-38: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Handle the token error before using response.

tokenEvents.get() can resolve with an error plus a null response, so destructuring response first drops the actual failure and falls back to the generic access-token message. Inspect the returned error object instead of immediately extracting response.

💡 Proposed fix to handle token retrieval errors
     if (DEBUGGER) debugger;
     const tokenEvents = user.tokens();
-    const { response: tokens } = await tokenEvents.get();
-    if (!tokens?.accessToken) {
-      throw new Error('Failed to retrieve access token');
+    const result = await tokenEvents.get();
+    
+    if (result.error) {
+      throw new Error(result.error.message || 'Failed to retrieve access token');
+    }
+    
+    const tokens = result.response;
+    if (!tokens?.accessToken) {
+      throw new Error('Failed to retrieve access token');
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@javascript/reactjs-todo-login-widget/client/utilities/request.js` around
lines 34 - 38, Update the token retrieval flow around tokenEvents.get() to
capture and inspect the full result before extracting response. Handle and
propagate the returned error when present, then validate accessToken and retain
the existing generic failure for missing tokens.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@javascript/reactjs-todo-login-widget/client/utilities/request.js`:
- Around line 34-38: Update the token retrieval flow around tokenEvents.get() to
capture and inspect the full result before extracting response. Handle and
propagate the returned error when present, then validate accessToken and retain
the existing generic failure for missing tokens.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aa8f6d9b-cc89-42a4-adae-9a5e01c39a17

📥 Commits

Reviewing files that changed from the base of the PR and between 7a74a8a and e8d8d15.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • javascript/reactjs-todo-davinci/README.md
  • javascript/reactjs-todo-journey/README.md
  • javascript/reactjs-todo-login-widget/README.md
  • javascript/reactjs-todo-login-widget/client/constants.js
  • javascript/reactjs-todo-login-widget/client/hooks/useLoginWidget.js
  • javascript/reactjs-todo-login-widget/client/index.js
  • javascript/reactjs-todo-login-widget/client/utilities/request.js
  • javascript/reactjs-todo-login-widget/package.json
  • javascript/reactjs-todo-login-widget/webpack.config.js
  • javascript/reactjs-todo-oidc/README.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • javascript/reactjs-todo-login-widget/package.json
  • javascript/reactjs-todo-oidc/README.md
  • javascript/reactjs-todo-login-widget/README.md
  • javascript/reactjs-todo-login-widget/webpack.config.js
  • javascript/reactjs-todo-login-widget/client/constants.js
  • javascript/reactjs-todo-journey/README.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@javascript/reactjs-todo-login-widget/client/hooks/useLoginWidget.js`:
- Around line 146-153: Update the waitForMount polling in useLoginWidget to
store its animation-frame ID, cancel any existing frame before starting a new
polling loop, and cancel the stored frame during widget cleanup. Ensure
unmounting and repeated early calls cannot leave parallel or indefinitely
scheduled polling loops.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 35a6dc4a-c4c5-409c-8eca-7177b5e3d94d

📥 Commits

Reviewing files that changed from the base of the PR and between e8d8d15 and 2aaba5a.

📒 Files selected for processing (2)
  • javascript/reactjs-todo-login-widget/client/context/auth.context.js
  • javascript/reactjs-todo-login-widget/client/hooks/useLoginWidget.js

Comment on lines +146 to +153
const waitForMount = () => {
if (widgetMountedRef.current) {
componentEvents.open();
} else {
requestAnimationFrame(waitForMount);
}
};
requestAnimationFrame(waitForMount);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Cancel readiness polling during cleanup.

If the component unmounts while waiting, widgetMountedRef remains false and waitForMount schedules animation frames forever. Repeated early calls also create parallel polling loops. Store the frame ID, cancel the previous poll before starting another, and cancel it in the widget cleanup.

Proposed fix
 const widgetMountedRef = useRef(false);
+const openFrameRef = useRef(null);

 return () => {
   widgetMountedRef.current = false;
+  if (openFrameRef.current !== null) {
+    cancelAnimationFrame(openFrameRef.current);
+    openFrameRef.current = null;
+  }
   widget.$destroy();
 };

+if (openFrameRef.current !== null) {
+  cancelAnimationFrame(openFrameRef.current);
+}
+
 const waitForMount = () => {
   if (widgetMountedRef.current) {
+    openFrameRef.current = null;
     componentEvents.open();
   } else {
-    requestAnimationFrame(waitForMount);
+    openFrameRef.current = requestAnimationFrame(waitForMount);
   }
 };
-requestAnimationFrame(waitForMount);
+openFrameRef.current = requestAnimationFrame(waitForMount);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@javascript/reactjs-todo-login-widget/client/hooks/useLoginWidget.js` around
lines 146 - 153, Update the waitForMount polling in useLoginWidget to store its
animation-frame ID, cancel any existing frame before starting a new polling
loop, and cancel the stored frame during widget cleanup. Ensure unmounting and
repeated early calls cannot leave parallel or indefinitely scheduled polling
loops.

@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch 4 times, most recently from 557a4cf to cdb4e6b Compare July 18, 2026 06:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
javascript/reactjs-todo-login-widget/client/context/auth.context.js (1)

51-55: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Return the subscription cleanup function instead of invoking it immediately.

Immediately invoking unsubscribe() cancels the subscription right after creation. If the underlying subscribe implementation is (or ever becomes) asynchronous, the callback may never execute, leading to an incorrect, unauthenticated state.

Additionally, returning the cleanup function is the standard React pattern for useEffect subscriptions. This prevents race conditions, cleans up on unmount, and keeps your React context automatically in sync with any future token state changes (e.g., token expiration or logout).

♻️ Proposed refactor
     const unsubscribe = user.tokens().subscribe((tokenState) => {
       const isAuthenticated = !!tokenState?.response?.accessToken;
       setAuthentication(isAuthenticated);
     });
-    unsubscribe();
+    return unsubscribe;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@javascript/reactjs-todo-login-widget/client/context/auth.context.js` around
lines 51 - 55, Update the subscription setup around user.tokens().subscribe in
the authentication effect to return the unsubscribe cleanup function instead of
invoking it immediately. Preserve the token callback’s setAuthentication
behavior and ensure React performs cleanup on unmount while continuing to
receive future token state changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@javascript/reactjs-todo-login-widget/client/context/auth.context.js`:
- Around line 51-55: Update the subscription setup around
user.tokens().subscribe in the authentication effect to return the unsubscribe
cleanup function instead of invoking it immediately. Preserve the token
callback’s setAuthentication behavior and ensure React performs cleanup on
unmount while continuing to receive future token state changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 056d9b9c-ba45-4e1d-b02d-30708893191f

📥 Commits

Reviewing files that changed from the base of the PR and between 7af5c19 and cdb4e6b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (12)
  • .github/workflows/CI.yml
  • javascript/reactjs-todo-davinci/README.md
  • javascript/reactjs-todo-journey/README.md
  • javascript/reactjs-todo-login-widget/README.md
  • javascript/reactjs-todo-login-widget/client/constants.js
  • javascript/reactjs-todo-login-widget/client/context/auth.context.js
  • javascript/reactjs-todo-login-widget/client/hooks/useLoginWidget.js
  • javascript/reactjs-todo-login-widget/client/index.js
  • javascript/reactjs-todo-login-widget/client/utilities/request.js
  • javascript/reactjs-todo-login-widget/package.json
  • javascript/reactjs-todo-login-widget/webpack.config.js
  • javascript/reactjs-todo-oidc/README.md
🚧 Files skipped from review as they are similar to previous changes (10)
  • .github/workflows/CI.yml
  • javascript/reactjs-todo-journey/README.md
  • javascript/reactjs-todo-login-widget/client/constants.js
  • javascript/reactjs-todo-login-widget/package.json
  • javascript/reactjs-todo-login-widget/client/utilities/request.js
  • javascript/reactjs-todo-login-widget/webpack.config.js
  • javascript/reactjs-todo-davinci/README.md
  • javascript/reactjs-todo-oidc/README.md
  • javascript/reactjs-todo-login-widget/README.md
  • javascript/reactjs-todo-login-widget/client/index.js

@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch 5 times, most recently from 8d8d49e to 9010cbd Compare July 18, 2026 07:03
Comment thread javascript/reactjs-todo-login-widget/client/constants.js Outdated
Comment thread javascript/reactjs-todo-login-widget/client/context/auth.context.js Outdated
@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch from 9010cbd to 4d2fa2a Compare July 20, 2026 23:23
@vatsalparikh
vatsalparikh marked this pull request as draft July 22, 2026 16:27
@vatsalparikh
vatsalparikh marked this pull request as ready for review July 22, 2026 21:25
SteinGabriel
SteinGabriel previously approved these changes Jul 22, 2026

@SteinGabriel SteinGabriel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look good. Tested it locally and everything works as expected.

@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch from d9f5ede to 74da094 Compare July 23, 2026 20:25
Comment thread javascript/reactjs-todo-login-widget/client/utilities/request.js
@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch 2 times, most recently from b667dc0 to 8aa7215 Compare July 24, 2026 19:30
@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch from 8aa7215 to 6028b2d Compare July 24, 2026 19:32
Comment thread javascript/reactjs-todo-login-widget/client/context/auth.context.js
cerebrl
cerebrl previously approved these changes Jul 27, 2026
Comment thread javascript/reactjs-todo-login-widget/client/utilities/request.js
@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch 2 times, most recently from b604224 to 753f52b Compare July 27, 2026 17:06
@vatsalparikh
vatsalparikh force-pushed the migrate-login-widget-2.0 branch from 753f52b to be867e3 Compare July 27, 2026 20:43
@vatsalparikh
vatsalparikh merged commit c74c68c into main Jul 27, 2026
17 checks passed
@vatsalparikh vatsalparikh removed the do not merge Do not merge label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants