@djangocfg/layouts 2.1.636 → 2.1.638
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/layouts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.638",
|
|
4
4
|
"description": "Simple, straightforward layout components for Next.js - import and use with props",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layouts",
|
|
@@ -91,11 +91,11 @@
|
|
|
91
91
|
"test": "vitest run"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@djangocfg/analytics": "^2.1.
|
|
95
|
-
"@djangocfg/api": "^2.1.
|
|
96
|
-
"@djangocfg/devtools": "^2.1.
|
|
97
|
-
"@djangocfg/i18n": "^2.1.
|
|
98
|
-
"@djangocfg/ui-core": "^2.1.
|
|
94
|
+
"@djangocfg/analytics": "^2.1.638",
|
|
95
|
+
"@djangocfg/api": "^2.1.638",
|
|
96
|
+
"@djangocfg/devtools": "^2.1.638",
|
|
97
|
+
"@djangocfg/i18n": "^2.1.638",
|
|
98
|
+
"@djangocfg/ui-core": "^2.1.638",
|
|
99
99
|
"@hookform/resolvers": "^5.2.2 || ^7.0.2",
|
|
100
100
|
"consola": "^3.4.2",
|
|
101
101
|
"lucide-react": "^1.68.0",
|
|
@@ -123,12 +123,12 @@
|
|
|
123
123
|
"qrcode.react": "^4.2.0"
|
|
124
124
|
},
|
|
125
125
|
"devDependencies": {
|
|
126
|
-
"@djangocfg/analytics": "^2.1.
|
|
127
|
-
"@djangocfg/api": "^2.1.
|
|
128
|
-
"@djangocfg/devtools": "^2.1.
|
|
129
|
-
"@djangocfg/i18n": "^2.1.
|
|
130
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
131
|
-
"@djangocfg/ui-core": "^2.1.
|
|
126
|
+
"@djangocfg/analytics": "^2.1.638",
|
|
127
|
+
"@djangocfg/api": "^2.1.638",
|
|
128
|
+
"@djangocfg/devtools": "^2.1.638",
|
|
129
|
+
"@djangocfg/i18n": "^2.1.638",
|
|
130
|
+
"@djangocfg/typescript-config": "^2.1.638",
|
|
131
|
+
"@djangocfg/ui-core": "^2.1.638",
|
|
132
132
|
"@storybook/react-vite": "^10.6.5",
|
|
133
133
|
"@types/node": "^25.9.5",
|
|
134
134
|
"@types/react": "19.3.0",
|
|
@@ -17,6 +17,7 @@ import React, { memo, useMemo } from 'react';
|
|
|
17
17
|
|
|
18
18
|
import { consumeSavedRedirect, useAuth, useCfgRouter } from '@djangocfg/api/auth';
|
|
19
19
|
import { useAnalytics } from '@djangocfg/analytics';
|
|
20
|
+
import { Alert, AlertDescription, AlertTitle, Preloader } from '@djangocfg/ui-core/components';
|
|
20
21
|
import { useAppT } from '@djangocfg/i18n';
|
|
21
22
|
|
|
22
23
|
import { Suspense } from '../../components';
|
|
@@ -51,6 +52,27 @@ export const AuthLayoutProvider = AuthLayoutContext.Provider;
|
|
|
51
52
|
|
|
52
53
|
// ─── Layout ──────────────────────────────────────────────────────────────────
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Single sign-in: the visitor was sent back to a host that could not see the shared session
|
|
57
|
+
* (`?sso_error=cookie`), so this host shows the form instead of sending them back again.
|
|
58
|
+
*/
|
|
59
|
+
function SsoCookieNotice() {
|
|
60
|
+
const [failed, setFailed] = React.useState(false);
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
setFailed(new URLSearchParams(window.location.search).get('sso_error') === 'cookie');
|
|
63
|
+
}, []);
|
|
64
|
+
if (!failed) return null;
|
|
65
|
+
return (
|
|
66
|
+
<Alert variant="destructive" className="mb-4">
|
|
67
|
+
<AlertTitle>The sign-in did not carry over to the site you came from</AlertTitle>
|
|
68
|
+
<AlertDescription>
|
|
69
|
+
Your browser did not share the session between the two sites (cookies for the whole domain are blocked, or the
|
|
70
|
+
sites are on different domains). Allow cookies for this domain and sign in again.
|
|
71
|
+
</AlertDescription>
|
|
72
|
+
</Alert>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
54
76
|
export const AuthLayout: React.FC<AuthLayoutProps> = (props) => {
|
|
55
77
|
const {
|
|
56
78
|
variant = 'fullsplit',
|
|
@@ -107,6 +129,13 @@ export const AuthLayout: React.FC<AuthLayoutProps> = (props) => {
|
|
|
107
129
|
[redirectUrl, onOAuthSuccess, onError],
|
|
108
130
|
);
|
|
109
131
|
|
|
132
|
+
// Single sign-in: a follower host never shows the form. The provider is already sending the
|
|
133
|
+
// visitor to the sign-in host (with `next`); this only keeps the form from flashing meanwhile.
|
|
134
|
+
const { sso, isAuthenticated } = useAuth();
|
|
135
|
+
if (sso?.enabled && !sso.isAuthHost && !isAuthenticated) {
|
|
136
|
+
return <Preloader variant="fullscreen" text="Redirecting to sign-in..." size="lg" />;
|
|
137
|
+
}
|
|
138
|
+
|
|
110
139
|
return (
|
|
111
140
|
<Suspense>
|
|
112
141
|
<AuthFormProvider {...props}>
|
|
@@ -124,6 +153,7 @@ export const AuthLayout: React.FC<AuthLayoutProps> = (props) => {
|
|
|
124
153
|
topBar={topBar}
|
|
125
154
|
className={className}
|
|
126
155
|
>
|
|
156
|
+
<SsoCookieNotice />
|
|
127
157
|
{/* Finishes a provider sign-in when the URL carries one */}
|
|
128
158
|
{oauthCallback}
|
|
129
159
|
|
|
@@ -12,6 +12,14 @@ Shell-based authentication layout with three visual variants:
|
|
|
12
12
|
floating over the `background` image; on mobile it collapses to a plain,
|
|
13
13
|
frameless centered form (no image, no glass, no sidebar).
|
|
14
14
|
|
|
15
|
+
## One sign-in host (SSO)
|
|
16
|
+
|
|
17
|
+
`BaseApp auth={{ sso: true }}` makes one host (`auth.<apex>`) the only place the form is shown. Elsewhere the layout is a
|
|
18
|
+
preloader and the provider sends the visitor to `{authHost}/auth?next=<page>`; after sign-in they return to `next`. On the
|
|
19
|
+
host, `?sso_error=cookie` (the shared cookie did not reach the site they came from) shows a notice and stops the send-back.
|
|
20
|
+
Off unless `sso` is set. Setup and the `next` rules: docs → *One sign-in host for subdomains*; code: `@djangocfg/api`
|
|
21
|
+
`auth/utils/sso.ts`.
|
|
22
|
+
|
|
15
23
|
## Where the brand goes
|
|
16
24
|
|
|
17
25
|
**One brand per screen, placed where there is room for it.** Pass `logo`; the
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { Check, FlaskConical, KeyRound, Loader2, RefreshCw } from 'lucide-react';
|
|
3
|
+
import { Check, Copy, FlaskConical, KeyRound, Loader2, RefreshCw } from 'lucide-react';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
Badge,
|
|
8
8
|
Button,
|
|
9
|
-
CopyButton,
|
|
10
9
|
Preloader,
|
|
11
10
|
SettingRow,
|
|
12
11
|
SettingsBlock,
|
|
13
12
|
} from '@djangocfg/ui-core/components';
|
|
14
|
-
import {
|
|
13
|
+
import { toast } from '@djangocfg/ui-core/hooks';
|
|
14
|
+
import { copyText, cn } from '@djangocfg/ui-core/lib';
|
|
15
|
+
import { useAppT } from '@djangocfg/i18n';
|
|
15
16
|
|
|
16
17
|
import { useSettingsLocale } from '../../i18n';
|
|
17
18
|
import { ApiKeyProvider, useApiKeyContext } from './context';
|
|
@@ -44,6 +45,39 @@ function isMasked(key: string): boolean {
|
|
|
44
45
|
return key.includes('•');
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Copies the key the row shows. The row is masked, so the full value is fetched at the click (the reveal call does not rotate the key and the
|
|
50
|
+
* mask stays on screen); a key that was just regenerated is already full and is copied as it is.
|
|
51
|
+
*/
|
|
52
|
+
function CopyKeyButton() {
|
|
53
|
+
const t = useAppT();
|
|
54
|
+
const { fullKey } = useApiKeyContext();
|
|
55
|
+
const [state, setState] = React.useState<'idle' | 'busy' | 'copied'>('idle');
|
|
56
|
+
const onClick = async () => {
|
|
57
|
+
setState('busy');
|
|
58
|
+
const key = await fullKey();
|
|
59
|
+
const ok = key ? await copyText(key) : false;
|
|
60
|
+
if (!ok) toast.error('Failed to copy the API key');
|
|
61
|
+
setState(ok ? 'copied' : 'idle');
|
|
62
|
+
if (ok) window.setTimeout(() => setState('idle'), 2000);
|
|
63
|
+
};
|
|
64
|
+
const label = state === 'copied' ? t('ui.actions.copied') : t('ui.actions.copyToClipboard');
|
|
65
|
+
return (
|
|
66
|
+
<Button
|
|
67
|
+
type="button"
|
|
68
|
+
variant="ghost"
|
|
69
|
+
size="icon"
|
|
70
|
+
className="shrink-0"
|
|
71
|
+
aria-label={label}
|
|
72
|
+
tooltip={label}
|
|
73
|
+
disabled={state === 'busy'}
|
|
74
|
+
onClick={onClick}
|
|
75
|
+
>
|
|
76
|
+
{state === 'busy' ? <Loader2 className="h-4 w-4 animate-spin" /> : state === 'copied' ? <Check className="h-4 w-4 text-success" /> : <Copy className="h-4 w-4" />}
|
|
77
|
+
</Button>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
47
81
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
48
82
|
// Inner component (uses context)
|
|
49
83
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -160,10 +194,10 @@ function ApiKeyCard() {
|
|
|
160
194
|
</span>
|
|
161
195
|
</div>
|
|
162
196
|
|
|
163
|
-
{/* Copy
|
|
197
|
+
{/* Copy always (a masked key is fetched at the click); Test only when the key is fresh (full key after regenerate) */}
|
|
198
|
+
<CopyKeyButton />
|
|
164
199
|
{isFresh && (
|
|
165
200
|
<>
|
|
166
|
-
<CopyButton value={apiKey} />
|
|
167
201
|
<Button
|
|
168
202
|
variant="secondary"
|
|
169
203
|
size="sm"
|
|
@@ -27,6 +27,8 @@ interface ApiKeyContextValue {
|
|
|
27
27
|
isRegenerating: boolean;
|
|
28
28
|
isFresh: boolean;
|
|
29
29
|
dismissFresh: () => void;
|
|
30
|
+
/** The full key for the clipboard: the one on screen when it is already full, else fetched (not rotated, not shown). `null` if it could not be read. */
|
|
31
|
+
fullKey: () => Promise<string | null>;
|
|
30
32
|
testKey: () => Promise<void>;
|
|
31
33
|
isTesting: boolean;
|
|
32
34
|
testResult: boolean | null;
|
|
@@ -45,7 +47,7 @@ export const useApiKeyContext = (): ApiKeyContextValue => {
|
|
|
45
47
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
46
48
|
|
|
47
49
|
export const ApiKeyProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
48
|
-
const { apiKey, reissuedAt, createdAt, isLoading, isRegenerating, isTesting, regenerate, testKey, refresh } = useApiKey();
|
|
50
|
+
const { apiKey, reissuedAt, createdAt, isLoading, isRegenerating, isTesting, regenerate, testKey, refresh, reveal } = useApiKey();
|
|
49
51
|
|
|
50
52
|
const LABELS = useSettingsCopy().apiKey;
|
|
51
53
|
const [isArmed, setIsArmed] = useState(false);
|
|
@@ -63,6 +65,15 @@ export const ApiKeyProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
|
|
63
65
|
refresh();
|
|
64
66
|
}, [refresh]);
|
|
65
67
|
|
|
68
|
+
const fullKey = useCallback(async () => {
|
|
69
|
+
if (apiKey && isFresh) return apiKey;
|
|
70
|
+
try {
|
|
71
|
+
return await reveal({ show: false });
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}, [apiKey, isFresh, reveal]);
|
|
76
|
+
|
|
66
77
|
const handleRegenerate = useCallback(async () => {
|
|
67
78
|
try {
|
|
68
79
|
setError(null);
|
|
@@ -107,13 +118,14 @@ export const ApiKeyProvider: React.FC<{ children: React.ReactNode }> = ({ childr
|
|
|
107
118
|
isRegenerating,
|
|
108
119
|
isFresh,
|
|
109
120
|
dismissFresh,
|
|
121
|
+
fullKey,
|
|
110
122
|
testKey: handleTest,
|
|
111
123
|
isTesting,
|
|
112
124
|
testResult,
|
|
113
125
|
}), [
|
|
114
126
|
LABELS, apiKey, reissuedAt, createdAt, isLoading, error,
|
|
115
127
|
isArmed, arm, disarm, handleRegenerate, isRegenerating, isFresh, dismissFresh,
|
|
116
|
-
handleTest, isTesting, testResult,
|
|
128
|
+
fullKey, handleTest, isTesting, testResult,
|
|
117
129
|
]);
|
|
118
130
|
|
|
119
131
|
return (
|