@lumoauth/react 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -255,7 +255,8 @@ is signed in.
255
255
  | `appearance` | `AppearanceProps` | none |
256
256
 
257
257
  **`<UserProfile>`** shows a profile card with account details, security status, roles, groups and
258
- a sign-out button.
258
+ a sign-out button. The MFA row, the roles and the groups appear only when the UserInfo response
259
+ holds the `mfa_enabled`, `roles` and `groups` claims. With the default scopes it holds none of them.
259
260
 
260
261
  ```tsx
261
262
  <UserProfile afterSignOutUrl="/" />
@@ -545,13 +546,41 @@ Every ready-made component accepts an `appearance` prop:
545
546
 
546
547
  | Option | Type | Description |
547
548
  |---|---|---|
548
- | `theme` | `'light' \| 'dark'` | Force a theme. The default follows the system setting. |
549
+ | `theme` | `'light' \| 'dark'` | Force a theme for this component. The default follows the system setting. |
549
550
  | `className` | `string` | Extra class on the component's root element |
550
551
  | `variables` | `Record<string, string>` | Values for CSS custom properties |
551
552
 
552
- Commonly changed properties: `--la-primary`, `--la-primary-hover`, `--la-bg`,
553
- `--la-text-primary`, `--la-text-secondary`, `--la-border`, `--la-radius-md` and
554
- `--la-font-family`. The stylesheet defines more for spacing, shadows, font sizes and states.
553
+ Commonly changed properties: `--la-primary`, `--la-primary-hover`, `--la-primary-text`, `--la-bg`,
554
+ `--la-text`, `--la-text-secondary`, `--la-border`, `--la-radius-md` and `--la-font-family`. The
555
+ stylesheet defines more for spacing, shadows, font sizes and states.
556
+
557
+ **Follow the theme of your app.** Without a choice the components follow the colour scheme of the
558
+ operating system, so a light app can get dark components. Choose the theme in one of three ways:
559
+
560
+ | Where | How |
561
+ |---|---|
562
+ | The whole app | `data-lumoauth-theme="light"` or `"dark"` on `<html>`, or the class `la-light` / `la-dark`. Change it when your theme switch changes. |
563
+ | A part of the page | The same attribute or class on any element that wraps the components |
564
+ | One component | `appearance={{ theme: 'light' }}` |
565
+
566
+ To use your own colours in both themes, map the properties to the design tokens of your app. The
567
+ values change with your theme, so the components follow it:
568
+
569
+ ```tsx
570
+ const appearance = {
571
+ variables: {
572
+ '--la-font-family': 'inherit',
573
+ '--la-bg': 'var(--card)',
574
+ '--la-text': 'var(--card-foreground)',
575
+ '--la-text-secondary': 'var(--muted-foreground)',
576
+ '--la-border': 'var(--border)',
577
+ '--la-primary': 'var(--primary)',
578
+ '--la-primary-text': 'var(--primary-foreground)',
579
+ },
580
+ };
581
+
582
+ <UserButton appearance={appearance} />
583
+ ```
555
584
 
556
585
  ## Sign-in strategies
557
586
 
package/dist/index.d.mts CHANGED
@@ -18,7 +18,10 @@ interface LumoAuthUser {
18
18
  avatarUrl?: string;
19
19
  /** Whether email has been verified */
20
20
  emailVerified: boolean;
21
- /** Whether MFA is enabled */
21
+ /**
22
+ * Whether MFA is enabled. Also `false` when the UserInfo response has no
23
+ * `mfa_enabled` claim; check `claims.mfa_enabled` to tell the two apart.
24
+ */
22
25
  mfaEnabled: boolean;
23
26
  /** List of role slugs */
24
27
  roles: string[];
@@ -94,7 +97,12 @@ interface LumoAuthProviderProps {
94
97
  children: React.ReactNode;
95
98
  }
96
99
  interface AppearanceProps {
97
- /** Force light or dark theme (defaults to system preference) */
100
+ /**
101
+ * Force the light or the dark theme for this component. Without it the
102
+ * component follows the nearest ancestor that has the class `la-light` /
103
+ * `la-dark` or the attribute `data-lumoauth-theme="light" | "dark"`, and
104
+ * otherwise the colour scheme of the operating system.
105
+ */
98
106
  theme?: 'light' | 'dark';
99
107
  /** Override CSS custom properties */
100
108
  variables?: Record<string, string>;
@@ -218,7 +226,9 @@ interface UserProfileProps {
218
226
  afterSignOutUrl?: string;
219
227
  /**
220
228
  * Display mode:
221
- * - `'full'` — shows all sections (account, security, roles)
229
+ * - `'full'` — shows all sections (account, security, roles). The MFA
230
+ * row and the roles and groups appear only when the UserInfo response
231
+ * holds those claims.
222
232
  * - `'compact'` — shows only account details
223
233
  * @default 'full'
224
234
  */
package/dist/index.d.ts CHANGED
@@ -18,7 +18,10 @@ interface LumoAuthUser {
18
18
  avatarUrl?: string;
19
19
  /** Whether email has been verified */
20
20
  emailVerified: boolean;
21
- /** Whether MFA is enabled */
21
+ /**
22
+ * Whether MFA is enabled. Also `false` when the UserInfo response has no
23
+ * `mfa_enabled` claim; check `claims.mfa_enabled` to tell the two apart.
24
+ */
22
25
  mfaEnabled: boolean;
23
26
  /** List of role slugs */
24
27
  roles: string[];
@@ -94,7 +97,12 @@ interface LumoAuthProviderProps {
94
97
  children: React.ReactNode;
95
98
  }
96
99
  interface AppearanceProps {
97
- /** Force light or dark theme (defaults to system preference) */
100
+ /**
101
+ * Force the light or the dark theme for this component. Without it the
102
+ * component follows the nearest ancestor that has the class `la-light` /
103
+ * `la-dark` or the attribute `data-lumoauth-theme="light" | "dark"`, and
104
+ * otherwise the colour scheme of the operating system.
105
+ */
98
106
  theme?: 'light' | 'dark';
99
107
  /** Override CSS custom properties */
100
108
  variables?: Record<string, string>;
@@ -218,7 +226,9 @@ interface UserProfileProps {
218
226
  afterSignOutUrl?: string;
219
227
  /**
220
228
  * Display mode:
221
- * - `'full'` — shows all sections (account, security, roles)
229
+ * - `'full'` — shows all sections (account, security, roles). The MFA
230
+ * row and the roles and groups appear only when the UserInfo response
231
+ * holds those claims.
222
232
  * - `'compact'` — shows only account details
223
233
  * @default 'full'
224
234
  */
package/dist/index.js CHANGED
@@ -71,36 +71,7 @@ function injectStyles() {
71
71
  document.head.appendChild(style);
72
72
  injected = true;
73
73
  }
74
- var CSS_CONTENT = `
75
- /* \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
76
- @lumoauth/react \u2014 Self-contained component styles
77
- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 */
78
-
79
- :root {
80
- --la-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
81
- --la-font-size-sm: 0.8125rem;
82
- --la-font-size-base: 0.875rem;
83
- --la-font-size-lg: 1rem;
84
- --la-font-size-xl: 1.25rem;
85
- --la-font-size-2xl: 1.5rem;
86
- --la-font-weight-normal: 400;
87
- --la-font-weight-medium: 500;
88
- --la-font-weight-semibold: 600;
89
-
90
- --la-radius-sm: 6px;
91
- --la-radius-md: 8px;
92
- --la-radius-lg: 12px;
93
- --la-radius-xl: 16px;
94
- --la-radius-full: 9999px;
95
-
96
- --la-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
97
- --la-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
98
- --la-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
99
- --la-shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
100
-
101
- --la-transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
102
-
103
- /* Light theme (default) */
74
+ var LIGHT_THEME = `
104
75
  --la-bg: #ffffff;
105
76
  --la-bg-subtle: #f8f9fb;
106
77
  --la-bg-muted: #f1f3f5;
@@ -120,11 +91,13 @@ var CSS_CONTENT = `
120
91
  --la-link: #7c5cfc;
121
92
  --la-overlay: rgba(0,0,0,0.5);
122
93
  --la-card-shadow: var(--la-shadow-xl);
123
- }
124
-
125
- /* Dark theme */
126
- [data-lumoauth-theme="dark"],
127
- .la-dark {
94
+ --la-badge-success-bg: #dcfce7;
95
+ --la-badge-success-text: #166534;
96
+ --la-badge-warning-bg: #fef9c3;
97
+ --la-badge-warning-text: #854d0e;
98
+ --la-badge-muted-bg: var(--la-bg-muted);
99
+ `;
100
+ var DARK_THEME = `
128
101
  --la-bg: #1a1a2e;
129
102
  --la-bg-subtle: #16213e;
130
103
  --la-bg-muted: #0f3460;
@@ -144,32 +117,71 @@ var CSS_CONTENT = `
144
117
  --la-link: #9d85f7;
145
118
  --la-overlay: rgba(0,0,0,0.7);
146
119
  --la-card-shadow: 0 20px 25px -5px rgba(0,0,0,0.3), 0 10px 10px -5px rgba(0,0,0,0.2);
120
+ --la-badge-success-bg: rgba(22, 163, 74, 0.15);
121
+ --la-badge-success-text: #4ade80;
122
+ --la-badge-warning-bg: rgba(234, 179, 8, 0.15);
123
+ --la-badge-warning-text: #facc15;
124
+ --la-badge-muted-bg: rgba(255, 255, 255, 0.08);
125
+ `;
126
+ var CSS_CONTENT = `
127
+ /* \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
128
+ @lumoauth/react \u2014 Self-contained component styles
129
+ \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 */
130
+
131
+ :root {
132
+ --la-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
133
+ --la-font-size-sm: 0.8125rem;
134
+ --la-font-size-base: 0.875rem;
135
+ --la-font-size-lg: 1rem;
136
+ --la-font-size-xl: 1.25rem;
137
+ --la-font-size-2xl: 1.5rem;
138
+ --la-font-weight-normal: 400;
139
+ --la-font-weight-medium: 500;
140
+ --la-font-weight-semibold: 600;
141
+
142
+ --la-radius-sm: 6px;
143
+ --la-radius-md: 8px;
144
+ --la-radius-lg: 12px;
145
+ --la-radius-xl: 16px;
146
+ --la-radius-full: 9999px;
147
+
148
+ --la-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
149
+ --la-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
150
+ --la-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
151
+ --la-shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
152
+
153
+ --la-transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
154
+ }
155
+
156
+ /*
157
+ * Colours. Three ways choose the theme, from weakest to strongest:
158
+ *
159
+ * 1. the operating system (prefers-color-scheme), when nothing else is set;
160
+ * 2. a class or attribute on an ancestor or on the component itself:
161
+ * .la-light / .la-dark, or data-lumoauth-theme="light" | "dark"
162
+ * (the appearance.theme prop sets the class on the component);
163
+ * 3. appearance.variables, which is inline style on the component.
164
+ *
165
+ * The light values are repeated under .la-light so that a component can be
166
+ * light on a page that the operating system made dark.
167
+ */
168
+ :root,
169
+ .la-light,
170
+ [data-lumoauth-theme="light"] {
171
+ ${LIGHT_THEME}
147
172
  }
148
173
 
149
174
  @media (prefers-color-scheme: dark) {
150
175
  :root:not([data-lumoauth-theme="light"]):not(.la-light) {
151
- --la-bg: #1a1a2e;
152
- --la-bg-subtle: #16213e;
153
- --la-bg-muted: #0f3460;
154
- --la-bg-hover: #1a3a6a;
155
- --la-border: #2a2a4a;
156
- --la-border-focus: #9d85f7;
157
- --la-text: #e8e8f0;
158
- --la-text-secondary: #a0a0b8;
159
- --la-text-muted: #6a6a88;
160
- --la-primary: #9d85f7;
161
- --la-primary-hover: #b39dff;
162
- --la-primary-text: #1a1a2e;
163
- --la-danger: #ff6b6b;
164
- --la-danger-bg: #2d1b1b;
165
- --la-success: #51cf66;
166
- --la-success-bg: #1b2d1b;
167
- --la-link: #9d85f7;
168
- --la-overlay: rgba(0,0,0,0.7);
169
- --la-card-shadow: 0 20px 25px -5px rgba(0,0,0,0.3), 0 10px 10px -5px rgba(0,0,0,0.2);
176
+ ${DARK_THEME}
170
177
  }
171
178
  }
172
179
 
180
+ .la-dark,
181
+ [data-lumoauth-theme="dark"] {
182
+ ${DARK_THEME}
183
+ }
184
+
173
185
  /* \u2500\u2500\u2500 Card Container \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
174
186
 
175
187
  .la-card {
@@ -659,7 +671,7 @@ var CSS_CONTENT = `
659
671
  justify-content: center;
660
672
  font-family: var(--la-font-family);
661
673
  font-weight: var(--la-font-weight-semibold);
662
- color: #fff;
674
+ color: var(--la-primary-text);
663
675
  background: var(--la-primary);
664
676
  overflow: hidden;
665
677
  flex-shrink: 0;
@@ -683,6 +695,9 @@ var CSS_CONTENT = `
683
695
 
684
696
  /* \u2500\u2500\u2500 UserProfile Card \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
685
697
 
698
+ /* --la-text-primary is an optional override that older apps set. It has no
699
+ default: the text colour is --la-text. */
700
+
686
701
  .la-profile-card {
687
702
  max-width: 420px;
688
703
  }
@@ -716,7 +731,7 @@ var CSS_CONTENT = `
716
731
  .la-profile-name {
717
732
  font-size: var(--la-font-size-lg);
718
733
  font-weight: var(--la-font-weight-semibold);
719
- color: var(--la-text-primary);
734
+ color: var(--la-text-primary, var(--la-text));
720
735
  line-height: 1.3;
721
736
  overflow: hidden;
722
737
  text-overflow: ellipsis;
@@ -750,7 +765,7 @@ var CSS_CONTENT = `
750
765
  gap: 0.625rem;
751
766
  padding: 0.5rem 0;
752
767
  font-size: var(--la-font-size-base);
753
- color: var(--la-text-primary);
768
+ color: var(--la-text-primary, var(--la-text));
754
769
  }
755
770
 
756
771
  .la-profile-row svg {
@@ -784,32 +799,17 @@ var CSS_CONTENT = `
784
799
  }
785
800
 
786
801
  .la-badge-success {
787
- background: #dcfce7;
788
- color: #166534;
802
+ background: var(--la-badge-success-bg);
803
+ color: var(--la-badge-success-text);
789
804
  }
790
805
 
791
806
  .la-badge-warning {
792
- background: #fef9c3;
793
- color: #854d0e;
807
+ background: var(--la-badge-warning-bg);
808
+ color: var(--la-badge-warning-text);
794
809
  }
795
810
 
796
811
  .la-badge-muted {
797
- background: var(--la-bg-muted);
798
- color: var(--la-text-secondary);
799
- }
800
-
801
- .la-dark .la-badge-success {
802
- background: rgba(22, 163, 74, 0.15);
803
- color: #4ade80;
804
- }
805
-
806
- .la-dark .la-badge-warning {
807
- background: rgba(234, 179, 8, 0.15);
808
- color: #facc15;
809
- }
810
-
811
- .la-dark .la-badge-muted {
812
- background: rgba(255, 255, 255, 0.08);
812
+ background: var(--la-badge-muted-bg);
813
813
  color: var(--la-text-secondary);
814
814
  }
815
815
 
@@ -848,7 +848,7 @@ var CSS_CONTENT = `
848
848
  .la-btn-outline {
849
849
  background: transparent;
850
850
  border: 1px solid var(--la-border);
851
- color: var(--la-text-primary);
851
+ color: var(--la-text-primary, var(--la-text));
852
852
  padding: 0.625rem 1rem;
853
853
  border-radius: var(--la-radius-md);
854
854
  font-size: var(--la-font-size-base);
@@ -1179,7 +1179,7 @@ function LumoAuthProvider({
1179
1179
  params.set("id_token_hint", idToken);
1180
1180
  }
1181
1181
  const logoutUrl = `${domain.replace(/\/+$/, "")}/orgs/${safeOrgId}/api/v1/oauth/logout?${params.toString()}`;
1182
- if (accessToken) {
1182
+ if (accessToken && !storage?.serverManaged) {
1183
1183
  authModule.revokeToken(accessToken, accessToken).catch(() => {
1184
1184
  });
1185
1185
  }
@@ -1188,7 +1188,7 @@ function LumoAuthProvider({
1188
1188
  window.location.replace(logoutUrl);
1189
1189
  await new Promise(() => {
1190
1190
  });
1191
- }, [authModule, domain, orgId, afterSignOutUrl, session, dispatch]);
1191
+ }, [authModule, domain, orgId, afterSignOutUrl, session, storage, dispatch]);
1192
1192
  (0, import_react.useEffect)(() => {
1193
1193
  let cancelled = false;
1194
1194
  async function init() {
@@ -1928,11 +1928,12 @@ function UserAvatar({
1928
1928
  appearance
1929
1929
  }) {
1930
1930
  const { user, isSignedIn } = useLumoAuthContext();
1931
+ const themeClass = appearance?.theme === "dark" ? "la-dark" : appearance?.theme === "light" ? "la-light" : "";
1931
1932
  if (!isSignedIn || !user) {
1932
1933
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1933
1934
  "span",
1934
1935
  {
1935
- className: `la-avatar la-avatar-${shape} ${appearance?.className || ""}`,
1936
+ className: `la-avatar la-avatar-${shape} ${themeClass} ${appearance?.className || ""}`,
1936
1937
  style: {
1937
1938
  width: size,
1938
1939
  height: size,
@@ -1947,7 +1948,6 @@ function UserAvatar({
1947
1948
  );
1948
1949
  }
1949
1950
  const initials = [user.firstName, user.lastName].filter(Boolean).map((n) => n.charAt(0).toUpperCase()).join("") || user.email.charAt(0).toUpperCase();
1950
- const themeClass = appearance?.theme === "dark" ? "la-dark" : appearance?.theme === "light" ? "la-light" : "";
1951
1951
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1952
1952
  "span",
1953
1953
  {
@@ -1996,6 +1996,9 @@ var ICONS = {
1996
1996
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("line", { x1: "21", y1: "12", x2: "9", y2: "12" })
1997
1997
  ] })
1998
1998
  };
1999
+ function hasMfaStatus(user) {
2000
+ return typeof user.claims?.mfa_enabled === "boolean";
2001
+ }
1999
2002
  function UserProfile({
2000
2003
  afterSignOutUrl,
2001
2004
  mode = "full",
@@ -2047,7 +2050,7 @@ function UserProfile({
2047
2050
  ] })
2048
2051
  ] }),
2049
2052
  mode === "full" && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2050
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-section", children: [
2053
+ hasMfaStatus(user) && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-section", children: [
2051
2054
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "la-profile-section-title", children: "Security" }),
2052
2055
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "la-profile-row", children: [
2053
2056
  ICONS.shield,