Skip to content

Refactor branding preference fetching logic#406

Merged
brionmario merged 5 commits into
asgardeo:mainfrom
kavindadimuthu:fix/branding-issue
May 12, 2026
Merged

Refactor branding preference fetching logic#406
brionmario merged 5 commits into
asgardeo:mainfrom
kavindadimuthu:fix/branding-issue

Conversation

@kavindadimuthu
Copy link
Copy Markdown
Contributor

@kavindadimuthu kavindadimuthu commented Mar 17, 2026

Purpose

This pull request updates the branding preferences logic in the SDK to ensure branding is only fetched and applied when explicitly enabled, rather than by default. The changes clarify the documentation and adjust the code to require inheritFromBranding to be set to true for branding to be fetched.

Branding preferences logic update:

  • Updated the documentation for the inheritFromBranding property in the ThemePreferences interface to clarify that branding is only fetched when explicitly enabled, and defaults to false.
  • Changed the branding fetch logic in AsgardeoProvider to only fetch branding when preferences.theme.inheritFromBranding is true, rather than when it is not false.
  • Updated the enabled prop for branding in AsgardeoProvider to require preferences.theme.inheritFromBranding to be true.

Related Issues

Related PRs

  • N/A

Checklist

  • Followed the CONTRIBUTING guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Unit tests provided. (Add links if there are any)

Security checks

Summary by CodeRabbit

  • Documentation

    • Clarified that branding inheritance is disabled by default and requires explicit opt-in configuration.
  • Improvements

    • Enhanced error logging and messaging when branding preference retrieval fails.
  • Chores

    • Applied minor dependency release bumps.

Review Change Stack

@kavindadimuthu kavindadimuthu force-pushed the fix/branding-issue branch 2 times, most recently from ac11887 to 45dafe3 Compare March 25, 2026 13:05
Comment thread packages/javascript/src/api/getBrandingPreference.ts Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50350138-8a92-45b3-885e-1377bf190e62

📥 Commits

Reviewing files that changed from the base of the PR and between f0cf50d and 118e96e.

📒 Files selected for processing (4)
  • .changeset/cold-games-lead.md
  • packages/javascript/src/api/getBrandingPreference.ts
  • packages/javascript/src/models/config.ts
  • packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx
✅ Files skipped from review due to trivial changes (2)
  • packages/javascript/src/models/config.ts
  • .changeset/cold-games-lead.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/javascript/src/api/getBrandingPreference.ts
  • packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

📝 Walkthrough

Walkthrough

This PR makes branding an explicit opt-in (default false), updates the JSDoc and changeset to reflect that default, and adds richer warning logging when the branding-preference API call fails; the React provider is updated to only fetch/apply branding when opt-in is true.

Changes

Branding Preference Default and Error Handling

Layer / File(s) Summary
Configuration default and documentation
.changeset/cold-games-lead.md, packages/javascript/src/models/config.ts
Changeset declares minor bumps and JSDoc for inheritFromBranding now documents that branding is fetched/applied when enabled and that the default is false.
Branding preference API error logging
packages/javascript/src/api/getBrandingPreference.ts
Adds Platform, identifyPlatform, and logger imports; on non-OK responses parses error text with JSON fallback, selects platform-specific console guidance, and emits a logger.warn containing the error description and suppression/resolution hints.
Provider branding opt-in enforcement
packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx
AsgardeoProvider now only auto-fetches and enables BrandingProvider when preferences?.theme?.inheritFromBranding === true, enforcing explicit opt-in.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • brionmario
  • DonOmalVindula

Poem

🐰 A little hop, a gentle tweak,
Opt-in for colors, no need to peek.
When APIs stumble, a warning sings,
Guiding console notes and helpful things.
Preferences chosen, tidy and bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Refactor branding preference fetching logic' accurately describes the main change: updating how branding preferences are fetched and applied in the SDK with explicit opt-in behavior.
Description check ✅ Passed The PR description comprehensively covers the purpose of changes, links to related issue #384, and includes the template checklist sections, though security checks remain incomplete.
Linked Issues check ✅ Passed The PR addresses issue #384 by refactoring branding preference logic to require explicit opt-in (inheritFromBranding === true), preventing unwanted API calls and gracefully handling errors via enhanced logging in getBrandingPreference.ts.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #384: updating branding preference handling, improving error logging, and clarifying documentation to prevent unintended API calls.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

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

🧹 Nitpick comments (1)
packages/javascript/src/api/getBrandingPreference.ts (1)

161-161: ⚡ Quick win

Remove the as any type assertion.

The type assertion bypasses TypeScript's type safety. identifyPlatform expects a config object with a baseUrl property, so you should pass a properly typed object:

♻️ Proposed fix
-      const platform: Platform = identifyPlatform({baseUrl} as any);
+      const platform: Platform = identifyPlatform({baseUrl});
🤖 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 `@packages/javascript/src/api/getBrandingPreference.ts` at line 161, The code
uses an unsafe cast when calling identifyPlatform; remove the "as any" and pass
a properly typed config object instead—e.g., construct an object with the
baseUrl property typed to the expected config interface and call
identifyPlatform(config) so the platform variable is assigned via
identifyPlatform({ baseUrl }) without any type assertion; update any surrounding
variable or parameter types so baseUrl matches the identifyPlatform config type.
🤖 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 `@packages/javascript/src/api/getBrandingPreference.ts`:
- Around line 183-185: The logger.warn call in getBrandingPreference.ts contains
React-specific guidance referencing `<AsgardeoProvider>`; update the message to
be framework-agnostic by removing the component reference and instead
instructing users to update the SDK configuration (e.g., set
preferences.theme.inheritFromBranding to false) or consult the
platformConsoleGuidance; modify the string built with errorDescription and
platformConsoleGuidance so it reads something like "To stop fetching branding
preferences, set preferences.theme.inheritFromBranding to false in your SDK
configuration" while keeping the existing errorDescription and
platformConsoleGuidance variables.

---

Nitpick comments:
In `@packages/javascript/src/api/getBrandingPreference.ts`:
- Line 161: The code uses an unsafe cast when calling identifyPlatform; remove
the "as any" and pass a properly typed config object instead—e.g., construct an
object with the baseUrl property typed to the expected config interface and call
identifyPlatform(config) so the platform variable is assigned via
identifyPlatform({ baseUrl }) without any type assertion; update any surrounding
variable or parameter types so baseUrl matches the identifyPlatform config type.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 26aa7525-73cd-4f21-88bf-863c010a94a1

📥 Commits

Reviewing files that changed from the base of the PR and between a7839e8 and f0cf50d.

📒 Files selected for processing (4)
  • .changeset/cold-games-lead.md
  • packages/javascript/src/api/getBrandingPreference.ts
  • packages/javascript/src/models/config.ts
  • packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

Comment on lines +183 to +185
logger.warn(
`[BrandingError] ${errorDescription} To resolve this issue, please ${platformConsoleGuidance}. If you want to suppress this warning and stop fetching branding preferences, set \`<AsgardeoProvider>\` -> \`preferences\` -> \`theme\` -> \`inheritFromBranding\` to false.`,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid React-specific guidance in the JavaScript package.

The warning message references <AsgardeoProvider>, which is a React-specific component. Since this is in the @asgardeo/javascript package (not @asgardeo/react), the guidance could be confusing or incorrect for developers using this SDK in non-React contexts (vanilla JS, Vue, Angular, etc.).

Consider making the guidance framework-agnostic:

💡 Proposed fix to use framework-agnostic guidance
       logger.warn(
-        `[BrandingError] ${errorDescription} To resolve this issue, please ${platformConsoleGuidance}. If you want to suppress this warning and stop fetching branding preferences, set \`<AsgardeoProvider>\` -> \`preferences\` -> \`theme\` -> \`inheritFromBranding\` to false.`,
+        `[BrandingError] ${errorDescription} To resolve this issue, please ${platformConsoleGuidance}. If you want to suppress this warning and stop fetching branding preferences, set the \`preferences.theme.inheritFromBranding\` configuration option to false.`,
       );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.warn(
`[BrandingError] ${errorDescription} To resolve this issue, please ${platformConsoleGuidance}. If you want to suppress this warning and stop fetching branding preferences, set \`<AsgardeoProvider>\` -> \`preferences\` -> \`theme\` -> \`inheritFromBranding\` to false.`,
);
logger.warn(
`[BrandingError] ${errorDescription} To resolve this issue, please ${platformConsoleGuidance}. If you want to suppress this warning and stop fetching branding preferences, set the \`preferences.theme.inheritFromBranding\` configuration option to false.`,
);
🤖 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 `@packages/javascript/src/api/getBrandingPreference.ts` around lines 183 - 185,
The logger.warn call in getBrandingPreference.ts contains React-specific
guidance referencing `<AsgardeoProvider>`; update the message to be
framework-agnostic by removing the component reference and instead instructing
users to update the SDK configuration (e.g., set
preferences.theme.inheritFromBranding to false) or consult the
platformConsoleGuidance; modify the string built with errorDescription and
platformConsoleGuidance so it reads something like "To stop fetching branding
preferences, set preferences.theme.inheritFromBranding to false in your SDK
configuration" while keeping the existing errorDescription and
platformConsoleGuidance variables.

@asgardeo-github-bot
Copy link
Copy Markdown

🦋 Changeset detected

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

@brionmario brionmario merged commit feb455a into asgardeo:main May 12, 2026
7 of 9 checks passed
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.

Gracefully handle branding preferences API call error message in React SDK

3 participants