Skip to content

Oauth setup#3538

Merged
Baalmart merged 4 commits into
stagingfrom
oauth-setup
May 25, 2026
Merged

Oauth setup#3538
Baalmart merged 4 commits into
stagingfrom
oauth-setup

Conversation

@OchiengPaul442

@OchiengPaul442 OchiengPaul442 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included issue number in the "Closes #ISSUE-NUMBER" part of the "What are the relevant tickets?" section to link the issue.
  • I've updated corresponding documentation for the changes in this PR.
  • I have written unit and/or e2e tests for my change(s).

How should this be manually tested?

  • Please include the steps to be done inorder to setup and test this PR.

What are the relevant tickets?

Screenshots (optional)

Summary by CodeRabbit

  • New Features

    • Added server-backed session refresh after password setting to ensure backend synchronization.
  • Bug Fixes

    • Improved user feedback with differentiated success and warning messages during password setup.
  • Refactor

    • Updated subscription status UI component for better visual presentation.
    • Restructured session token management and OAuth profile fetching logic.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@OchiengPaul442, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 22 minutes and 1 second.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cdfd1138-3cb5-452c-9e98-9315aa971e9f

📥 Commits

Reviewing files that changed from the base of the PR and between 70da385 and 67ffef5.

📒 Files selected for processing (2)
  • src/platform/src/modules/billing/components/SubscriptionSection.tsx
  • src/platform/src/shared/components/auth/SetPasswordPromptDialog.tsx
📝 Walkthrough

Walkthrough

This PR refactors session authentication architecture by moving token fields from the user object to the top-level session, introduces enhanced OAuth profile fetching with abort/timeout support, and integrates server-backed session verification into the password dialog. Additionally, the subscription status UI now uses a Banner component with severity levels.

Changes

Session Architecture and Auth Verification

Layer / File(s) Summary
Session Type Refinement
src/platform/src/next-auth.d.ts, src/platform/src/shared/types/global.d.ts
SessionUser type narrows Session.user to identity fields only (_id, firstName, lastName); ambient next-auth token augmentations removed from global declarations. Token fields move to top-level session object.
Enhanced OAuth Profile Fetching
src/platform/src/shared/lib/oauth-session.ts
New fetchEnhancedUserProfile function with timeout-based abort, external signal support, optional JWT authorization header, and response normalization. verifyBackendOAuthSession refactored to accept options and delegate to the enhanced fetch.
NextAuth Session Callback Refactor
src/platform/src/shared/lib/auth.ts
OAuth profile fetch delegated to fetchEnhancedUserProfile; session callback reshaped to place accessToken, expiresAt, authMethods at top-level session while session.user receives only identity fields.
Session Token Access & API Client
src/platform/src/shared/services/sessionAuthToken.ts, src/platform/src/shared/services/apiClient.ts
Token extraction reads only top-level session.accessToken without fallback to nested session.user.accessToken; API client refresh flow updated to use same top-level source.
SetPasswordPromptDialog Server-Backed Session Refresh
src/platform/src/shared/components/auth/SetPasswordPromptDialog.tsx
Adds abort-controller-backed in-flight request cancellation, mount state tracking, and refreshSessionState helper that calls verifyBackendOAuthSession and dispatches outcome-specific success/warning toasts (fresh/fallback/failed). Dialog closes on successful refresh.

Subscription Section Banner Update

Layer / File(s) Summary
Subscription Status Banner Rendering
src/platform/src/modules/billing/components/SubscriptionSection.tsx
Banner component imported; statusNotice object refactored to use severity (warning/info) instead of tone CSS strings for past_due, cancelled, paused, and non-free renewal-off states; render path updated to pass severity and message content to Banner.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • Baalmart
  • Codebmk

Poem

🔐 Tokens rise from user's nest,
To session's heart—a fresh request,
OAuth profiles fetch with care,
Abort control floats through the air,
Passwords set with server's grace,
Identity finds its proper place. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Oauth setup' is vague and generic, failing to convey the actual scope of changes which involve substantial refactoring of authentication handling, session management, and API token flow across multiple files. Consider a more descriptive title like 'Refactor OAuth session management and move token fields to session root' to better reflect the significant architectural changes being made.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch oauth-setup

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

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 and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
src/platform/src/shared/components/auth/SetPasswordPromptDialog.tsx (1)

273-277: ⚡ Quick win

Remove redundant nextAuthMethods redeclaration.

nextAuthMethods is already declared at lines 231-235 with identical logic and remains in scope within the catch block. This redeclaration is unnecessary.

       if (message.toLowerCase().includes('already set')) {
-        const nextAuthMethods: AuthMethods = {
-          ...DEFAULT_AUTH_METHODS,
-          ...authMethods,
-          password: true,
-        };
         const refreshOutcome = await refreshSessionState(nextAuthMethods);
🤖 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 `@src/platform/src/shared/components/auth/SetPasswordPromptDialog.tsx` around
lines 273 - 277, Remove the redundant redeclaration of nextAuthMethods inside
the catch block: reuse the existing nextAuthMethods (declared earlier at lines
231-235) instead of reassigning it again; locate the catch block in
SetPasswordPromptDialog where nextAuthMethods, DEFAULT_AUTH_METHODS, and
authMethods are referenced and delete the duplicate const nextAuthMethods = {
...DEFAULT_AUTH_METHODS, ...authMethods, password: true } so the code uses the
already-in-scope nextAuthMethods variable.
src/platform/src/shared/lib/auth.ts (1)

54-89: 💤 Low value

Consider consolidating duplicate normalizeAuthMethods and AUTH_METHOD_KEYS.

Both auth.ts and oauth-session.ts define identical AUTH_METHOD_KEYS arrays and normalizeAuthMethods functions. If these diverge in the future, it could lead to subtle inconsistencies.

You could export normalizeAuthMethods from oauth-session.ts and import it here, or extract it into a shared utility.

🤖 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 `@src/platform/src/shared/lib/auth.ts` around lines 54 - 89, The file defines
duplicate AUTH_METHOD_KEYS and normalizeAuthMethods which are identical to ones
in oauth-session.ts; extract AUTH_METHOD_KEYS and normalizeAuthMethods into a
shared utility module (or export the implementation from oauth-session.ts) and
import them here to avoid divergence. Update references in this file to use the
shared normalizeAuthMethods and AUTH_METHOD_KEYS symbols (or the exported
normalizeAuthMethods) and remove the local duplicate definitions so both auth.ts
and oauth-session.ts rely on the single shared implementation.
🤖 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 `@src/platform/src/shared/components/auth/SetPasswordPromptDialog.tsx`:
- Around line 273-277: Remove the redundant redeclaration of nextAuthMethods
inside the catch block: reuse the existing nextAuthMethods (declared earlier at
lines 231-235) instead of reassigning it again; locate the catch block in
SetPasswordPromptDialog where nextAuthMethods, DEFAULT_AUTH_METHODS, and
authMethods are referenced and delete the duplicate const nextAuthMethods = {
...DEFAULT_AUTH_METHODS, ...authMethods, password: true } so the code uses the
already-in-scope nextAuthMethods variable.

In `@src/platform/src/shared/lib/auth.ts`:
- Around line 54-89: The file defines duplicate AUTH_METHOD_KEYS and
normalizeAuthMethods which are identical to ones in oauth-session.ts; extract
AUTH_METHOD_KEYS and normalizeAuthMethods into a shared utility module (or
export the implementation from oauth-session.ts) and import them here to avoid
divergence. Update references in this file to use the shared
normalizeAuthMethods and AUTH_METHOD_KEYS symbols (or the exported
normalizeAuthMethods) and remove the local duplicate definitions so both auth.ts
and oauth-session.ts rely on the single shared implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ef6757b7-8e2c-4153-9571-cbf938c31e1f

📥 Commits

Reviewing files that changed from the base of the PR and between 59f2eb4 and 70da385.

📒 Files selected for processing (8)
  • src/platform/src/modules/billing/components/SubscriptionSection.tsx
  • src/platform/src/next-auth.d.ts
  • src/platform/src/shared/components/auth/SetPasswordPromptDialog.tsx
  • src/platform/src/shared/lib/auth.ts
  • src/platform/src/shared/lib/oauth-session.ts
  • src/platform/src/shared/services/apiClient.ts
  • src/platform/src/shared/services/sessionAuthToken.ts
  • src/platform/src/shared/types/global.d.ts
💤 Files with no reviewable changes (1)
  • src/platform/src/shared/types/global.d.ts

@github-actions

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@github-actions

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@Baalmart
Baalmart merged commit d658c0b into staging May 25, 2026
19 of 20 checks passed
@Baalmart
Baalmart deleted the oauth-setup branch May 25, 2026 18:04
@Baalmart Baalmart mentioned this pull request May 25, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants