@prenta/admin 2.17.0 → 2.17.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/CHANGELOG.md +72 -0
- package/dist/AdminRoot.d.ts.map +1 -1
- package/dist/AdminRoot.js +8 -0
- package/dist/AdminRoot.js.map +1 -1
- package/dist/__tests__/components/attribution-rows.test.js +12 -3
- package/dist/__tests__/components/attribution-rows.test.js.map +1 -1
- package/dist/__tests__/components/schedule-publish-dialog.render.test.d.ts +2 -0
- package/dist/__tests__/components/schedule-publish-dialog.render.test.d.ts.map +1 -0
- package/dist/__tests__/components/schedule-publish-dialog.render.test.js +78 -0
- package/dist/__tests__/components/schedule-publish-dialog.render.test.js.map +1 -0
- package/dist/__tests__/layout/shell-nav.render.test.js +106 -27
- package/dist/__tests__/layout/shell-nav.render.test.js.map +1 -1
- package/dist/__tests__/test-env-storage.test.d.ts +2 -0
- package/dist/__tests__/test-env-storage.test.d.ts.map +1 -0
- package/dist/__tests__/test-env-storage.test.js +28 -0
- package/dist/__tests__/test-env-storage.test.js.map +1 -0
- package/dist/__tests__/views/account-setup-gate.render.test.d.ts +2 -0
- package/dist/__tests__/views/account-setup-gate.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/account-setup-gate.render.test.js +103 -0
- package/dist/__tests__/views/account-setup-gate.render.test.js.map +1 -0
- package/dist/__tests__/views/login-mfa.render.test.js +33 -0
- package/dist/__tests__/views/login-mfa.render.test.js.map +1 -1
- package/dist/components/SchedulePublishDialog.d.ts +7 -1
- package/dist/components/SchedulePublishDialog.d.ts.map +1 -1
- package/dist/components/SchedulePublishDialog.js +6 -5
- package/dist/components/SchedulePublishDialog.js.map +1 -1
- package/dist/layout/MobileTabBar.d.ts +7 -4
- package/dist/layout/MobileTabBar.d.ts.map +1 -1
- package/dist/layout/MobileTabBar.js +41 -17
- package/dist/layout/MobileTabBar.js.map +1 -1
- package/dist/lib/entry-attribution.d.ts.map +1 -1
- package/dist/lib/entry-attribution.js +6 -4
- package/dist/lib/entry-attribution.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/views/AccountSetupGate.d.ts +17 -0
- package/dist/views/AccountSetupGate.d.ts.map +1 -0
- package/dist/views/AccountSetupGate.js +69 -0
- package/dist/views/AccountSetupGate.js.map +1 -0
- package/dist/views/DocumentEdit.d.ts.map +1 -1
- package/dist/views/DocumentEdit.js +1 -1
- package/dist/views/DocumentEdit.js.map +1 -1
- package/dist/views/Login.d.ts.map +1 -1
- package/dist/views/Login.js +50 -2
- package/dist/views/Login.js.map +1 -1
- package/dist/views/page-editor/PageSectionEditor.d.ts.map +1 -1
- package/dist/views/page-editor/PageSectionEditor.js +1 -1
- package/dist/views/page-editor/PageSectionEditor.js.map +1 -1
- package/dist/views/post-editor/PostSectionEditor.d.ts.map +1 -1
- package/dist/views/post-editor/PostSectionEditor.js +1 -1
- package/dist/views/post-editor/PostSectionEditor.js.map +1 -1
- package/dist/views/profile/AccountSecurity.d.ts +5 -1
- package/dist/views/profile/AccountSecurity.d.ts.map +1 -1
- package/dist/views/profile/AccountSecurity.js +2 -1
- package/dist/views/profile/AccountSecurity.js.map +1 -1
- package/package.json +6 -6
- package/src/AdminRoot.tsx +15 -0
- package/src/__tests__/components/attribution-rows.test.ts +13 -3
- package/src/__tests__/components/schedule-publish-dialog.render.test.tsx +100 -0
- package/src/__tests__/layout/shell-nav.render.test.tsx +181 -29
- package/src/__tests__/test-env-storage.test.ts +28 -0
- package/src/__tests__/views/account-setup-gate.render.test.tsx +122 -0
- package/src/__tests__/views/login-mfa.render.test.tsx +42 -0
- package/src/components/SchedulePublishDialog.tsx +15 -4
- package/src/layout/MobileTabBar.tsx +57 -28
- package/src/lib/entry-attribution.ts +6 -4
- package/src/views/AccountSetupGate.tsx +198 -0
- package/src/views/DocumentEdit.tsx +1 -0
- package/src/views/Login.tsx +54 -2
- package/src/views/page-editor/PageSectionEditor.tsx +1 -0
- package/src/views/post-editor/PostSectionEditor.tsx +1 -0
- package/src/views/profile/AccountSecurity.tsx +7 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useId, useState, type FormEvent } from 'react'
|
|
4
|
+
import { AlertTriangle, Loader2 } from 'lucide-react'
|
|
5
|
+
import {
|
|
6
|
+
AuthBrandHero,
|
|
7
|
+
AuthPrentaFooter,
|
|
8
|
+
useAuthBrand,
|
|
9
|
+
type AuthBrandingConfig,
|
|
10
|
+
} from '../components/AuthBranding.js'
|
|
11
|
+
import { cmsApi } from '../lib/api.js'
|
|
12
|
+
import { AccountSecurity } from './profile/AccountSecurity.js'
|
|
13
|
+
|
|
14
|
+
export type AccountRestriction = 'password_reset' | 'mfa_setup'
|
|
15
|
+
|
|
16
|
+
export interface AccountSetupGateProps {
|
|
17
|
+
restriction: AccountRestriction
|
|
18
|
+
/** Called once the step is done. Defaults to a full reload so the host re-reads /auth/me. */
|
|
19
|
+
onComplete?: () => void
|
|
20
|
+
onLogout: () => void
|
|
21
|
+
branding?: AuthBrandingConfig
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function reload() {
|
|
25
|
+
if (typeof window !== 'undefined') window.location.reload()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Full-screen step a restricted session must finish before the admin opens
|
|
30
|
+
* (#1254): an administrator asked this user to change their password or to set
|
|
31
|
+
* up two-factor authentication, or the organization requires MFA. Every other
|
|
32
|
+
* admin request answers 403 SETUP_REQUIRED until it is done.
|
|
33
|
+
*/
|
|
34
|
+
export function AccountSetupGate({
|
|
35
|
+
restriction,
|
|
36
|
+
onComplete = reload,
|
|
37
|
+
onLogout,
|
|
38
|
+
branding,
|
|
39
|
+
}: AccountSetupGateProps) {
|
|
40
|
+
const brand = useAuthBrand(branding)
|
|
41
|
+
const headingId = useId()
|
|
42
|
+
const title =
|
|
43
|
+
restriction === 'password_reset' ? 'Change your password' : 'Set up two-factor authentication'
|
|
44
|
+
const intro =
|
|
45
|
+
restriction === 'password_reset'
|
|
46
|
+
? 'Your administrator asked you to choose a new password before you continue.'
|
|
47
|
+
: 'Two-factor authentication is required for your account. Set it up to continue.'
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className="bg-background flex min-h-screen items-center justify-center px-4 py-10">
|
|
51
|
+
<main aria-labelledby={headingId} className="w-full max-w-lg">
|
|
52
|
+
<div className="mb-8 text-center">
|
|
53
|
+
<AuthBrandHero brand={brand} />
|
|
54
|
+
<h1 id={headingId} className="text-foreground text-2xl font-medium">
|
|
55
|
+
{title}
|
|
56
|
+
</h1>
|
|
57
|
+
<p className="text-muted-foreground mt-2">{intro}</p>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
{restriction === 'password_reset' ? (
|
|
61
|
+
<ChangePasswordForm onDone={onComplete} />
|
|
62
|
+
) : (
|
|
63
|
+
<AccountSecurity onEnabled={onComplete} />
|
|
64
|
+
)}
|
|
65
|
+
|
|
66
|
+
<div className="mt-6 text-center">
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
onClick={onLogout}
|
|
70
|
+
className="text-muted-foreground hover:text-foreground text-sm font-medium"
|
|
71
|
+
>
|
|
72
|
+
Sign out
|
|
73
|
+
</button>
|
|
74
|
+
</div>
|
|
75
|
+
<AuthPrentaFooter />
|
|
76
|
+
</main>
|
|
77
|
+
</div>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function ChangePasswordForm({ onDone }: { onDone: () => void }) {
|
|
82
|
+
const currentId = useId()
|
|
83
|
+
const nextId = useId()
|
|
84
|
+
const confirmId = useId()
|
|
85
|
+
const errorId = useId()
|
|
86
|
+
const [current, setCurrent] = useState('')
|
|
87
|
+
const [next, setNext] = useState('')
|
|
88
|
+
const [confirm, setConfirm] = useState('')
|
|
89
|
+
const [error, setError] = useState('')
|
|
90
|
+
const [saving, setSaving] = useState(false)
|
|
91
|
+
|
|
92
|
+
const canSubmit = Boolean(current && next && confirm) && !saving
|
|
93
|
+
|
|
94
|
+
async function handleSubmit(e: FormEvent) {
|
|
95
|
+
e.preventDefault()
|
|
96
|
+
if (!canSubmit) return
|
|
97
|
+
if (next !== confirm) {
|
|
98
|
+
setError('The new passwords do not match.')
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
setError('')
|
|
102
|
+
setSaving(true)
|
|
103
|
+
try {
|
|
104
|
+
const res = await cmsApi<{ success?: boolean }>('/auth/password', {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
body: JSON.stringify({ currentPassword: current, newPassword: next }),
|
|
107
|
+
})
|
|
108
|
+
if (res.error) {
|
|
109
|
+
setError(res.error)
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
onDone()
|
|
113
|
+
} catch (err) {
|
|
114
|
+
setError(err instanceof Error ? err.message : 'Could not change your password.')
|
|
115
|
+
} finally {
|
|
116
|
+
setSaving(false)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const inputClass =
|
|
121
|
+
'border-border bg-input-background text-foreground focus-visible:border-ring focus-visible:ring-ring/50 w-full rounded-lg border px-3 py-2.5 focus-visible:ring-2 focus-visible:outline-none'
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<form
|
|
125
|
+
onSubmit={handleSubmit}
|
|
126
|
+
className="border-border bg-card space-y-5 rounded-xl border p-6 shadow-sm"
|
|
127
|
+
aria-describedby={error ? errorId : undefined}
|
|
128
|
+
>
|
|
129
|
+
{error && (
|
|
130
|
+
<div
|
|
131
|
+
id={errorId}
|
|
132
|
+
role="alert"
|
|
133
|
+
className="border-destructive/30 bg-destructive/10 flex items-start gap-3 rounded-lg border p-3"
|
|
134
|
+
>
|
|
135
|
+
<AlertTriangle className="text-destructive mt-0.5 h-5 w-5 shrink-0" aria-hidden="true" />
|
|
136
|
+
<p className="text-destructive text-sm">{error}</p>
|
|
137
|
+
</div>
|
|
138
|
+
)}
|
|
139
|
+
<div>
|
|
140
|
+
<label htmlFor={currentId} className="text-foreground mb-1.5 block text-sm font-medium">
|
|
141
|
+
Current password
|
|
142
|
+
</label>
|
|
143
|
+
<input
|
|
144
|
+
id={currentId}
|
|
145
|
+
type="password"
|
|
146
|
+
autoComplete="current-password"
|
|
147
|
+
value={current}
|
|
148
|
+
onChange={(e) => setCurrent(e.target.value)}
|
|
149
|
+
className={inputClass}
|
|
150
|
+
required
|
|
151
|
+
autoFocus
|
|
152
|
+
/>
|
|
153
|
+
</div>
|
|
154
|
+
<div>
|
|
155
|
+
<label htmlFor={nextId} className="text-foreground mb-1.5 block text-sm font-medium">
|
|
156
|
+
New password
|
|
157
|
+
</label>
|
|
158
|
+
<input
|
|
159
|
+
id={nextId}
|
|
160
|
+
type="password"
|
|
161
|
+
autoComplete="new-password"
|
|
162
|
+
value={next}
|
|
163
|
+
onChange={(e) => setNext(e.target.value)}
|
|
164
|
+
className={inputClass}
|
|
165
|
+
required
|
|
166
|
+
/>
|
|
167
|
+
</div>
|
|
168
|
+
<div>
|
|
169
|
+
<label htmlFor={confirmId} className="text-foreground mb-1.5 block text-sm font-medium">
|
|
170
|
+
Confirm new password
|
|
171
|
+
</label>
|
|
172
|
+
<input
|
|
173
|
+
id={confirmId}
|
|
174
|
+
type="password"
|
|
175
|
+
autoComplete="new-password"
|
|
176
|
+
value={confirm}
|
|
177
|
+
onChange={(e) => setConfirm(e.target.value)}
|
|
178
|
+
className={inputClass}
|
|
179
|
+
required
|
|
180
|
+
/>
|
|
181
|
+
</div>
|
|
182
|
+
<button
|
|
183
|
+
type="submit"
|
|
184
|
+
disabled={!canSubmit}
|
|
185
|
+
className="bg-primary text-primary-foreground hover:bg-primary/90 flex w-full items-center justify-center gap-2 rounded-lg py-2.5 font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50"
|
|
186
|
+
>
|
|
187
|
+
{saving ? (
|
|
188
|
+
<>
|
|
189
|
+
<Loader2 className="h-4 w-4 animate-spin" aria-hidden="true" />
|
|
190
|
+
Saving...
|
|
191
|
+
</>
|
|
192
|
+
) : (
|
|
193
|
+
'Change password'
|
|
194
|
+
)}
|
|
195
|
+
</button>
|
|
196
|
+
</form>
|
|
197
|
+
)
|
|
198
|
+
}
|
package/src/views/Login.tsx
CHANGED
|
@@ -22,6 +22,49 @@ export interface CaptchaConfig {
|
|
|
22
22
|
*/
|
|
23
23
|
type LoginBrandingConfig = AuthBrandingConfig
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* After an OAuth sign-in for a TOTP user, the server holds the MFA-pending
|
|
27
|
+
* token in an HttpOnly cookie and redirects here with `?mfa=totp` (#1251). The
|
|
28
|
+
* code step then sends an empty token and `/auth/totp/login` reads the cookie.
|
|
29
|
+
*/
|
|
30
|
+
const COOKIE_MFA_PENDING = ''
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Messages the OAuth callback may put in `?error=` that are safe to show as
|
|
34
|
+
* they are: fixed text from `handleOAuthCallback` (and the account-state
|
|
35
|
+
* messages it shares with password login) that tells the user what to do.
|
|
36
|
+
* Anything else (a provider's own text, or a crafted link) gets the generic
|
|
37
|
+
* line, so the sign-in screen can't be made to show arbitrary text.
|
|
38
|
+
*/
|
|
39
|
+
const OAUTH_ERROR_MESSAGES = new Set([
|
|
40
|
+
'Account is deactivated',
|
|
41
|
+
'Account is suspended',
|
|
42
|
+
'Account is locked',
|
|
43
|
+
'An account already exists for this email. Sign in with your password and link your account from Settings to enable OAuth.',
|
|
44
|
+
'This provider did not verify your email address, so it cannot be used to sign in to an existing account. Sign in with your original method and link this provider from Settings.',
|
|
45
|
+
'No account found for this email. Ask an administrator to invite you before signing in with OAuth.',
|
|
46
|
+
])
|
|
47
|
+
const OAUTH_ERROR_FALLBACK = 'Sign-in with that provider did not complete. Try again.'
|
|
48
|
+
|
|
49
|
+
/** Reads and removes the OAuth callback's `?mfa=` / `?error=` from the URL. */
|
|
50
|
+
function takeOAuthRedirectParams(): { mfa: boolean; error: string | null } {
|
|
51
|
+
if (typeof window === 'undefined') return { mfa: false, error: null }
|
|
52
|
+
const params = new URLSearchParams(window.location.search)
|
|
53
|
+
const mfa = params.get('mfa') === 'totp'
|
|
54
|
+
const raw = params.get('error')
|
|
55
|
+
if (!mfa && raw === null) return { mfa: false, error: null }
|
|
56
|
+
params.delete('mfa')
|
|
57
|
+
params.delete('error')
|
|
58
|
+
const qs = params.toString()
|
|
59
|
+
window.history.replaceState(
|
|
60
|
+
window.history.state,
|
|
61
|
+
'',
|
|
62
|
+
`${window.location.pathname}${qs ? `?${qs}` : ''}${window.location.hash}`,
|
|
63
|
+
)
|
|
64
|
+
const error = raw === null ? null : OAUTH_ERROR_MESSAGES.has(raw) ? raw : OAUTH_ERROR_FALLBACK
|
|
65
|
+
return { mfa, error }
|
|
66
|
+
}
|
|
67
|
+
|
|
25
68
|
export interface LoginProps {
|
|
26
69
|
onLogin: (
|
|
27
70
|
email: string,
|
|
@@ -254,6 +297,15 @@ export function Login({
|
|
|
254
297
|
|
|
255
298
|
const brand = useAuthBrand(branding)
|
|
256
299
|
|
|
300
|
+
// Arriving from an OAuth callback: open the code step for a TOTP user, or
|
|
301
|
+
// show why the provider sign-in was refused. Read after mount so the server
|
|
302
|
+
// render and the first client render match.
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
const { mfa, error: oauthError } = takeOAuthRedirectParams()
|
|
305
|
+
if (mfa) setMfaPendingToken(COOKIE_MFA_PENDING)
|
|
306
|
+
else if (oauthError) setError(oauthError)
|
|
307
|
+
}, [])
|
|
308
|
+
|
|
257
309
|
useCaptchaScript(captchaConfig?.provider, captchaConfig?.siteKey)
|
|
258
310
|
|
|
259
311
|
const loggedOut = hasLoggedOutQuery()
|
|
@@ -300,7 +352,7 @@ export function Login({
|
|
|
300
352
|
const handleVerifyTotp = async (e: FormEvent) => {
|
|
301
353
|
e.preventDefault()
|
|
302
354
|
const code = totpCode.trim()
|
|
303
|
-
if (!code ||
|
|
355
|
+
if (!code || mfaPendingToken === null) return
|
|
304
356
|
|
|
305
357
|
setTotpError('')
|
|
306
358
|
|
|
@@ -353,7 +405,7 @@ export function Login({
|
|
|
353
405
|
<p className="text-muted-foreground mt-2">{brandTagline}</p>
|
|
354
406
|
</div>
|
|
355
407
|
|
|
356
|
-
{mfaPendingToken ? (
|
|
408
|
+
{mfaPendingToken !== null ? (
|
|
357
409
|
<form
|
|
358
410
|
onSubmit={handleVerifyTotp}
|
|
359
411
|
className="border-border bg-card space-y-5 rounded-xl border p-6 shadow-sm"
|
|
@@ -1204,6 +1204,7 @@ export function PageSectionEditor({
|
|
|
1204
1204
|
<SchedulePublishDialog
|
|
1205
1205
|
collectionSlug={PAGES_COLLECTION}
|
|
1206
1206
|
documentId={page.id}
|
|
1207
|
+
status={page.status}
|
|
1207
1208
|
scheduledAt={page.scheduledAt}
|
|
1208
1209
|
scheduledUnpublishAt={page.scheduledUnpublishAt}
|
|
1209
1210
|
open={scheduleOpen}
|
|
@@ -1075,6 +1075,7 @@ export function PostSectionEditor({
|
|
|
1075
1075
|
<SchedulePublishDialog
|
|
1076
1076
|
collectionSlug={postType}
|
|
1077
1077
|
documentId={post.id}
|
|
1078
|
+
status={post.status}
|
|
1078
1079
|
scheduledAt={post.scheduledAt}
|
|
1079
1080
|
scheduledUnpublishAt={post.scheduledUnpublishAt}
|
|
1080
1081
|
open={scheduleOpen}
|
|
@@ -26,7 +26,12 @@ function FieldError({ id, message }: { id: string; message: string | null }) {
|
|
|
26
26
|
)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export
|
|
29
|
+
export interface AccountSecurityProps {
|
|
30
|
+
/** Called once MFA has been switched on (the account setup step, #1254). */
|
|
31
|
+
onEnabled?: () => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function AccountSecurity({ onEnabled }: AccountSecurityProps = {}) {
|
|
30
35
|
const headingId = useId()
|
|
31
36
|
const pwId = useId()
|
|
32
37
|
const pwErrId = useId()
|
|
@@ -81,6 +86,7 @@ export function AccountSecurity() {
|
|
|
81
86
|
}
|
|
82
87
|
toast.success('Two-factor authentication is now enabled.')
|
|
83
88
|
resetSetup()
|
|
89
|
+
onEnabled?.()
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
async function handleDisable() {
|