-
Notifications
You must be signed in to change notification settings - Fork 0
auto-resolve sso provider icons via simple icons #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,58 @@ | ||
| import type { ReactNode } from "react"; | ||
| import { | ||
| AppleMark, | ||
| BuildingIcon, | ||
| FacebookMark, | ||
| GitHubMark, | ||
| GoogleMark, | ||
| KeyIcon, | ||
| MicrosoftMark, | ||
| } from "./icons"; | ||
| import { useState, type ReactNode } from "react"; | ||
| import { BuildingIcon, KeyIcon } from "./icons"; | ||
|
|
||
| export interface SSOProviderInfo { | ||
| label: string; | ||
| icon: ReactNode; | ||
| } | ||
|
|
||
| const NON_BRAND_ICONS: Record<string, { label: string; icon: ReactNode }> = { | ||
| passkey: { label: "Passkey", icon: <KeyIcon className="kma-sso-icon" /> }, | ||
| sso: { label: "SSO", icon: <BuildingIcon className="kma-sso-icon" /> }, | ||
| saml: { label: "SSO", icon: <BuildingIcon className="kma-sso-icon" /> }, | ||
| }; | ||
|
|
||
| function slugify(provider: string): string { | ||
| return provider.toLowerCase().replace(/[^a-z0-9]/g, ""); | ||
| } | ||
|
|
||
| function titleCase(provider: string): string { | ||
| return provider | ||
| .split(/[\s_-]+/) | ||
| .filter(Boolean) | ||
| .map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()) | ||
| .join(" "); | ||
| } | ||
|
|
||
| function SSOProviderIcon({ provider }: { provider: string }) { | ||
| const [errored, setErrored] = useState(false); | ||
| const slug = slugify(provider); | ||
| const letter = provider.trim().charAt(0).toUpperCase() || "?"; | ||
|
|
||
| if (!slug || errored) { | ||
| return ( | ||
| <span className="kma-sso-icon kma-sso-icon--letter" aria-hidden="true"> | ||
| {letter} | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <img | ||
| src={`https://cdn.simpleicons.org/${slug}`} | ||
| alt="" | ||
| className="kma-sso-icon" | ||
| onError={() => setErrored(true)} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export function getSSOProviderInfo(provider: string): SSOProviderInfo { | ||
| const p = provider.toLowerCase(); | ||
| if (p.includes("google")) | ||
| return { label: "Google", icon: <GoogleMark className="kma-sso-icon" /> }; | ||
| if (p.includes("github")) | ||
| return { label: "GitHub", icon: <GitHubMark className="kma-sso-icon" /> }; | ||
| if (p.includes("microsoft") || p.includes("azure")) | ||
| return { | ||
| label: "Microsoft", | ||
| icon: <MicrosoftMark className="kma-sso-icon" />, | ||
| }; | ||
| if (p.includes("facebook")) | ||
| return { | ||
| label: "Facebook", | ||
| icon: <FacebookMark className="kma-sso-icon" />, | ||
| }; | ||
| if (p.includes("apple")) | ||
| return { label: "Apple", icon: <AppleMark className="kma-sso-icon" /> }; | ||
| if (p.includes("saml") || p.includes("sso")) | ||
| return { label: "SSO", icon: <BuildingIcon className="kma-sso-icon" /> }; | ||
| if (p.includes("passkey")) | ||
| return { label: "Passkey", icon: <KeyIcon className="kma-sso-icon" /> }; | ||
| return { label: provider, icon: null }; | ||
| const key = slugify(provider); | ||
| const nonBrand = NON_BRAND_ICONS[key]; | ||
| if (nonBrand) return nonBrand; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-brand providers lose substring matching, breaking compound namesMedium Severity The old code used Additional Locations (1)Reviewed by Cursor Bugbot for commit 0c8c226. Configure here. |
||
| return { | ||
| label: titleCase(provider), | ||
| icon: <SSOProviderIcon provider={provider} />, | ||
| }; | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale error state persists across provider prop changes
Low Severity
SSOProviderIconstores CDN load failure inerroredstate viauseState, but never resets it when theproviderprop changes. If a CDN request fails for one provider and then the component receives a differentprovider(e.g.,ssoProviderchanges in the parent while the tree position stays mounted), the staleerrored = truecauses the new provider to immediately render the letter-avatar fallback instead of attempting its own CDN fetch.Reviewed by Cursor Bugbot for commit 0c8c226. Configure here.