@kidecms/core 0.30.1 → 0.31.1

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.
@@ -233,6 +233,14 @@ export default function cmsIntegration(options?: CmsIntegrationOptions): AstroIn
233
233
 
234
234
  // Inject admin pages
235
235
  injectRoute({ pattern: "/admin/login", entrypoint: new URL("../routes/admin/login.astro", import.meta.url) });
236
+ injectRoute({
237
+ pattern: "/admin/login/verify",
238
+ entrypoint: new URL("../routes/admin/login/verify.astro", import.meta.url),
239
+ });
240
+ injectRoute({
241
+ pattern: "/admin/account",
242
+ entrypoint: new URL("../routes/admin/account.astro", import.meta.url),
243
+ });
236
244
  injectRoute({
237
245
  pattern: "/admin/forgot-password",
238
246
  entrypoint: new URL("../routes/admin/forgot-password.astro", import.meta.url),
@@ -293,6 +301,19 @@ export default function cmsIntegration(options?: CmsIntegrationOptions): AstroIn
293
301
  pattern: "/api/cms/auth/invite",
294
302
  entrypoint: new URL("../routes/api/auth/invite.ts", import.meta.url),
295
303
  });
304
+ injectRoute({
305
+ pattern: "/api/cms/auth/login/verify",
306
+ entrypoint: new URL("../routes/api/auth/login/verify.ts", import.meta.url),
307
+ });
308
+ injectRoute({
309
+ pattern: "/api/cms/auth/account",
310
+ entrypoint: new URL("../routes/api/auth/account.ts", import.meta.url),
311
+ });
312
+ // Better Auth's own endpoints (OAuth callbacks, two-factor, passkeys) — allowlisted inside.
313
+ injectRoute({
314
+ pattern: "/api/cms/auth/[...all]",
315
+ entrypoint: new URL("../routes/api/auth/[...all].ts", import.meta.url),
316
+ });
296
317
  injectRoute({
297
318
  pattern: "/api/cms/assets/upload",
298
319
  entrypoint: new URL("../routes/api/assets/upload.ts", import.meta.url),
@@ -14,8 +14,9 @@ declare module "virtual:kide/api" {
14
14
 
15
15
  declare module "virtual:kide/schema" {
16
16
  const cmsTables: Record<string, { main: any; translations?: any }>;
17
- export const cmsSessions: any;
18
- export const cmsPasswordResets: any;
17
+ export const cmsAuthSessions: any;
18
+ export const cmsAuthAccounts: any;
19
+ export const cmsAuthVerifications: any;
19
20
  export const cmsRateLimits: any;
20
21
  export { cmsTables };
21
22
  }
@@ -1,11 +1,18 @@
1
1
  import { defineMiddleware } from "astro:middleware";
2
2
  import type { APIContext, MiddlewareNext } from "astro";
3
- import { publicOrigin, resolveAdminAuth, runWithRequestScope } from "../core";
3
+ import {
4
+ getSsoDenial,
5
+ publicOrigin,
6
+ registerAuthConfig,
7
+ resolveAdminAuth,
8
+ resolveAdminSession,
9
+ runWithRequestScope,
10
+ } from "../core";
4
11
  import type { RequestScope, SessionUser } from "../core";
5
12
  import { eq } from "drizzle-orm";
6
13
 
7
14
  import config from "virtual:kide/config";
8
- import { getSessionUser } from "virtual:kide/runtime";
15
+ import "virtual:kide/runtime";
9
16
  import { getDb } from "virtual:kide/db";
10
17
 
11
18
  let hasUsers: boolean | null = null;
@@ -26,6 +33,7 @@ const normalizeCustomUser = (value: Record<string, unknown> | null): SessionUser
26
33
  };
27
34
 
28
35
  export const onRequest = defineMiddleware(async (context, next) => {
36
+ registerAuthConfig(config);
29
37
  // Establish a per-request scope for EVERY request (including public pages and custom public
30
38
  // API routes) so deferred work (audit/search/webhook-enqueue) is kept alive only for THIS
31
39
  // request — never routed to the module-level script fallback, whose promises aren't attached
@@ -57,7 +65,7 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
57
65
 
58
66
  // `?preview` exposes draft content on public pages; require a session (unauth → strip it).
59
67
  if (context.url.searchParams.has("preview")) {
60
- const previewUser = await getSessionUser(context.request);
68
+ const previewUser = (await resolveAdminSession(context.request))?.user ?? null;
61
69
  if (!previewUser) {
62
70
  const clean = new URL(context.url);
63
71
  clean.searchParams.delete("preview");
@@ -69,16 +77,15 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
69
77
  const isAdminRoute = pathname.startsWith("/admin");
70
78
  const isAdminApiRoute = pathname.startsWith("/api/cms");
71
79
  const isLoginPage = pathname === "/admin/login";
72
- const isLoginApi = pathname === "/api/cms/auth/login";
73
80
  const isForgotPasswordPage = pathname === "/admin/forgot-password";
74
- const isForgotPasswordApi = pathname === "/api/cms/auth/forgot-password";
75
81
  const isResetPasswordPage = pathname === "/admin/reset-password";
76
- const isResetPasswordApi = pathname === "/api/cms/auth/reset-password";
77
- const isSsoAuthApi = pathname.startsWith("/api/cms/auth/sso/");
82
+ // Every /api/cms/auth/* route guards itself: Kide's own (login, setup, invite, …)
83
+ // and Better Auth's (OAuth callbacks, two-factor, passkeys) through the catch-all.
84
+ const isAuthApi = pathname.startsWith("/api/cms/auth/");
85
+ const isTwoFactorPage = pathname === "/admin/login/verify";
78
86
  const isSetupPage = pathname === "/admin/setup";
79
87
  const isSetupApi = pathname === "/api/cms/auth/setup";
80
88
  const isInvitePage = pathname === "/admin/invite";
81
- const isInviteApi = pathname === "/api/cms/auth/invite";
82
89
 
83
90
  // Public despite the /api/cms prefix: cmsImageUrl() puts these URLs on public pages.
84
91
  // Only reads files under public/, which are served unauthenticated anyway.
@@ -90,7 +97,8 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
90
97
 
91
98
  // Security headers for all admin routes
92
99
  const isAuthPath =
93
- pathname.startsWith("/api/cms/auth/") ||
100
+ isAuthApi ||
101
+ isTwoFactorPage ||
94
102
  isLoginPage ||
95
103
  isSetupPage ||
96
104
  isInvitePage ||
@@ -191,24 +199,21 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
191
199
  return context.redirect("/admin/login");
192
200
  }
193
201
 
194
- // Always allow login page, login API, and cron/webhook endpoints (they have
202
+ // Always allow the sign-in pages, auth API, and cron/webhook endpoints (they have
195
203
  // their own auth: bearer secret for cron, HMAC signature for webhooks)
196
204
  const isCronApi = pathname === "/api/cms/cron/publish" || pathname === "/api/cms/cron/tasks";
197
205
  const isWebhookApi = pathname.startsWith("/api/cms/webhooks/");
198
206
  const isFormSubmit = pathname.startsWith("/api/cms/forms/submit/");
199
207
  if (
200
208
  isLoginPage ||
201
- isLoginApi ||
209
+ isTwoFactorPage ||
202
210
  isForgotPasswordPage ||
203
- isForgotPasswordApi ||
204
211
  isResetPasswordPage ||
205
- isResetPasswordApi ||
206
- isSsoAuthApi ||
212
+ isAuthApi ||
207
213
  isSetupApi ||
208
214
  isCronApi ||
209
215
  isWebhookApi ||
210
216
  isInvitePage ||
211
- isInviteApi ||
212
217
  isFormSubmit
213
218
  ) {
214
219
  return serve();
@@ -216,10 +221,19 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
216
221
 
217
222
  const auth = resolveAdminAuth(config);
218
223
  const customProvider = config.admin?.auth?.provider;
224
+ const session =
225
+ auth.provider === "custom" && typeof customProvider === "object"
226
+ ? null
227
+ : await resolveAdminSession(context.request);
219
228
  const user =
220
229
  auth.provider === "custom" && typeof customProvider === "object"
221
230
  ? normalizeCustomUser(await customProvider.getSession(context.request))
222
- : await getSessionUser(context.request);
231
+ : (session?.user ?? null);
232
+ // A sliding-session refresh re-issues the cookie; pass it through.
233
+ const withSessionCookies = (response: Response) => {
234
+ for (const cookie of session?.setCookies ?? []) response.headers.append("Set-Cookie", cookie);
235
+ return response;
236
+ };
223
237
 
224
238
  // Non-httpOnly hint for the public-site edit bar: lets the injected client skip
225
239
  // the session check entirely for anonymous visitors. Carries no auth value — the
@@ -238,13 +252,31 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
238
252
  };
239
253
 
240
254
  if (!user) {
255
+ const denial = getSsoDenial(context.request);
241
256
  // API routes → 401
242
257
  if (isAdminApiRoute) {
243
- return new Response(JSON.stringify({ error: "Unauthorized" }), {
258
+ const error = denial
259
+ ? denial.kind === "revoked"
260
+ ? "sso_access_revoked"
261
+ : "sso_reauthentication_required"
262
+ : null;
263
+ return new Response(JSON.stringify({ error: "Unauthorized", ...(error ? { code: error } : {}) }), {
244
264
  status: 401,
245
265
  headers: { "Content-Type": "application/json" },
246
266
  });
247
267
  }
268
+ // The provider refused the user: say so instead of a bare login page.
269
+ if (denial?.kind === "revoked") {
270
+ return withEditorHint(context.redirect("/admin/login?error=sso_access_revoked"), false);
271
+ }
272
+ // Back through the provider — usually a silent hop while its own session is alive.
273
+ if (denial?.kind === "reauth") {
274
+ const returnTo = `${pathname}${context.url.search}`;
275
+ return withEditorHint(
276
+ context.redirect(`/api/cms/auth/sso/${denial.providerId}/start?returnTo=${encodeURIComponent(returnTo)}`),
277
+ false,
278
+ );
279
+ }
248
280
  // Admin pages → redirect to login
249
281
  return withEditorHint(context.redirect("/admin/login"), false);
250
282
  }
@@ -252,5 +284,13 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
252
284
  // Attach user to locals for downstream use
253
285
  context.locals.user = user;
254
286
 
255
- return withEditorHint(await serve(), true);
287
+ // `mfa.require`: password users enroll an authenticator before anything else.
288
+ if (session?.mfaEnrollmentRequired && pathname !== "/admin/account") {
289
+ if (isAdminApiRoute) {
290
+ return Response.json({ error: "Two-factor authentication must be set up first." }, { status: 403 });
291
+ }
292
+ return withSessionCookies(context.redirect("/admin/account?mfa=required"));
293
+ }
294
+
295
+ return withSessionCookies(withEditorHint(await serve(), true));
256
296
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.30.1",
3
+ "version": "0.31.1",
4
4
  "description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
5
5
  "keywords": [
6
6
  "cms",
@@ -53,12 +53,15 @@
53
53
  "dependencies": {
54
54
  "@ai-sdk/openai": "^3.0.114",
55
55
  "@base-ui/react": "^1.8.0",
56
+ "@better-auth/passkey": "1.7.7",
57
+ "@better-auth/utils": "0.4.2",
56
58
  "@dnd-kit/core": "^6.3.1",
57
59
  "@dnd-kit/sortable": "^10.0.0",
58
60
  "@dnd-kit/utilities": "^3.2.2",
59
61
  "@modelcontextprotocol/sdk": "^1.30.0",
60
62
  "@radix-ui/react-dropdown-menu": "^2.1.24",
61
63
  "@radix-ui/react-popover": "^1.1.23",
64
+ "@simplewebauthn/browser": "^13.3.0",
62
65
  "@tanstack/react-table": "^8.21.3",
63
66
  "@tiptap/core": "3.31.3",
64
67
  "@tiptap/extension-image": "3.31.3",
@@ -70,6 +73,7 @@
70
73
  "@tiptap/starter-kit": "3.31.3",
71
74
  "@tiptap/suggestion": "3.31.3",
72
75
  "ai": "^6.0.286",
76
+ "better-auth": "1.7.7",
73
77
  "class-variance-authority": "^0.7.1",
74
78
  "clsx": "^2.1.1",
75
79
  "cmdk": "^1.1.1",
@@ -78,7 +82,8 @@
78
82
  "nanoid": "^6.0.1",
79
83
  "tailwind-merge": "^3.7.0",
80
84
  "tsx": "^4.23.13",
81
- "tw-animate-css": "^1.4.0"
85
+ "tw-animate-css": "^1.4.0",
86
+ "uqr": "^0.1.3"
82
87
  },
83
88
  "peerDependencies": {
84
89
  "astro": "^7.0.0",
@@ -0,0 +1,138 @@
1
+ ---
2
+ import AdminLayout from "../../admin/layouts/AdminLayout.astro";
3
+ import AdminCard from "../../admin/components/AdminCard.astro";
4
+ import PasskeySettings from "../../admin/components/PasskeySettings";
5
+ import TwoFactorSettings from "../../admin/components/TwoFactorSettings";
6
+ import { Input } from "../../admin/components/ui/input";
7
+ import { Label } from "../../admin/components/ui/label";
8
+ import { buttonVariants } from "../../admin/components/ui/button";
9
+ import { canRead } from "../../admin/lib/access";
10
+ import config from "virtual:kide/config";
11
+ import {
12
+ enforcedSsoProvider,
13
+ getAccountSecurity,
14
+ initDateFormat,
15
+ MIN_PASSWORD_LENGTH,
16
+ mfaRequiredFor,
17
+ resolveAdminAuth,
18
+ } from "../../core";
19
+
20
+ export const prerender = false;
21
+
22
+ initDateFormat(config, Astro.cookies.get("tz")?.value);
23
+
24
+ const user = Astro.locals.user;
25
+ if (!user) return Astro.redirect("/admin/login");
26
+
27
+ const auth = resolveAdminAuth(config);
28
+ const security = await getAccountSecurity(user.id);
29
+ const mfaRequired = mfaRequiredFor(auth, user.role);
30
+ // Domain-bound users sign in through their provider only; a stored password is unused.
31
+ const managedBy = enforcedSsoProvider(auth, user.email);
32
+ const usesPassword = security.hasPassword && !managedBy;
33
+ const mustEnroll = Astro.url.searchParams.get("mfa") === "required" && !security.twoFactorEnabled;
34
+ const ssoLabels = new Map(auth.ssoProviders.map((provider) => [provider.id, provider.label]));
35
+ const accessibleCollections = config.collections.filter((c) => canRead(config, user, c.slug));
36
+ ---
37
+
38
+ <AdminLayout title="Account | Kide CMS" collections={accessibleCollections} activeCollection="account">
39
+ <section class="max-w-3xl space-y-6 px-4 py-6 lg:py-8 lg:pr-8 lg:pl-12">
40
+ <div class="space-y-1">
41
+ <h1 class="text-2xl font-semibold tracking-tight">Account &amp; security</h1>
42
+ <p class="text-muted-foreground text-sm">{user.name} · {user.email} · {user.role}</p>
43
+ </div>
44
+
45
+ {
46
+ mustEnroll && (
47
+ <div class="rounded-lg border border-amber-300 bg-amber-50 px-4 py-3 text-sm text-amber-900 dark:border-amber-700 dark:bg-amber-500/10 dark:text-amber-100">
48
+ Your role requires two-factor authentication. Set up an authenticator app to continue to the admin.
49
+ </div>
50
+ )
51
+ }
52
+
53
+ <AdminCard
54
+ title="Sign-in methods"
55
+ description={managedBy ? `Your organization manages your sign-in through ${managedBy.label}.` : undefined}
56
+ >
57
+ <ul class="grid gap-2 text-sm">
58
+ {usesPassword && <li>Email and password</li>}
59
+ {security.ssoProviders.map((id) => <li>{ssoLabels.get(id) ?? id} (single sign-on)</li>)}
60
+ {
61
+ security.passkeys.length > 0 && (
62
+ <li>{security.passkeys.length === 1 ? "1 passkey" : `${security.passkeys.length} passkeys`}</li>
63
+ )
64
+ }
65
+ </ul>
66
+ <form method="post" action="/api/cms/auth/account" class="mt-4">
67
+ <input type="hidden" name="_action" value="revoke-other-sessions" />
68
+ <button class={buttonVariants({ variant: "outline" })} type="submit">Sign out on other devices</button>
69
+ </form>
70
+ </AdminCard>
71
+
72
+ {
73
+ usesPassword && (
74
+ <AdminCard title="Password">
75
+ <form method="post" action="/api/cms/auth/account" class="grid max-w-sm gap-4">
76
+ <input type="hidden" name="_action" value="change-password" />
77
+ <div class="grid gap-2">
78
+ <Label htmlFor="currentPassword">Current password</Label>
79
+ <Input
80
+ id="currentPassword"
81
+ name="currentPassword"
82
+ type="password"
83
+ autoComplete="current-password"
84
+ required
85
+ />
86
+ </div>
87
+ <div class="grid gap-2">
88
+ <Label htmlFor="newPassword">New password</Label>
89
+ <Input
90
+ id="newPassword"
91
+ name="newPassword"
92
+ type="password"
93
+ autoComplete="new-password"
94
+ placeholder={`Min ${MIN_PASSWORD_LENGTH} characters`}
95
+ required
96
+ />
97
+ </div>
98
+ <div class="grid gap-2">
99
+ <Label htmlFor="confirmPassword">Confirm new password</Label>
100
+ <Input id="confirmPassword" name="confirmPassword" type="password" autoComplete="new-password" required />
101
+ </div>
102
+ <div>
103
+ <button class={buttonVariants()} type="submit">
104
+ Change password
105
+ </button>
106
+ </div>
107
+ </form>
108
+ </AdminCard>
109
+ )
110
+ }
111
+
112
+ {
113
+ auth.mfa.totp && usesPassword && (
114
+ <AdminCard
115
+ title="Two-factor authentication"
116
+ description={
117
+ security.twoFactorEnabled
118
+ ? "On — signing in with your password also asks for a code from your authenticator app."
119
+ : "Add a code from an authenticator app to every password sign-in."
120
+ }
121
+ >
122
+ <TwoFactorSettings client:load enabled={security.twoFactorEnabled} required={mfaRequired} />
123
+ </AdminCard>
124
+ )
125
+ }
126
+
127
+ {
128
+ auth.mfa.passkeys && (
129
+ <AdminCard
130
+ title="Passkeys"
131
+ description="Sign in with your fingerprint, face or device PIN instead of a password."
132
+ >
133
+ <PasskeySettings client:load passkeys={security.passkeys} dateLocale={config.admin?.dateFormat} />
134
+ </AdminCard>
135
+ )
136
+ }
137
+ </section>
138
+ </AdminLayout>
@@ -5,7 +5,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../..
5
5
  import { Input } from "../../admin/components/ui/input";
6
6
  import { Label } from "../../admin/components/ui/label";
7
7
  import { buttonVariants } from "../../admin/components/ui/button";
8
- import { resolveAdminAuth } from "../../core";
8
+ import { passwordResetDelivery, resolveAdminAuth } from "../../core";
9
9
  import config from "virtual:kide/config";
10
10
 
11
11
  export const prerender = false;
@@ -13,6 +13,7 @@ export const prerender = false;
13
13
  const auth = resolveAdminAuth(config);
14
14
  if (!auth.password.forgotPassword) return Astro.redirect("/admin/login");
15
15
 
16
+ const delivery = passwordResetDelivery();
16
17
  const status = Astro.url.searchParams.get("status");
17
18
  ---
18
19
 
@@ -32,26 +33,45 @@ const status = Astro.url.searchParams.get("status");
32
33
  <Card>
33
34
  <CardHeader>
34
35
  <CardTitle>Reset password</CardTitle>
35
- <CardDescription>Enter your email and we'll send a reset link</CardDescription>
36
+ <CardDescription>
37
+ {delivery ? "Enter your email and we'll send a reset link" : "Reset by email isn't available"}
38
+ </CardDescription>
36
39
  </CardHeader>
37
40
  <CardContent>
38
41
  {
39
- status === "sent" && (
42
+ status === "sent" && delivery && (
40
43
  <div class="border-border bg-muted mb-4 rounded-lg border px-3 py-2 text-sm">
41
- If that account exists, a reset link has been sent.
44
+ {delivery === "email"
45
+ ? "If that account exists, a reset link has been sent."
46
+ : "Email isn't set up, so if that account exists, its reset link was printed in the dev server's terminal."}
47
+ </div>
48
+ )
49
+ }
50
+ {
51
+ delivery ? (
52
+ <form method="post" action="/api/cms/auth/forgot-password" class="grid gap-4">
53
+ <div class="grid gap-2">
54
+ <Label htmlFor="email">Email</Label>
55
+ <Input id="email" name="email" type="email" placeholder="admin@example.com" required autoFocus />
56
+ </div>
57
+ <button class={buttonVariants({ size: "lg", className: "w-full" })} type="submit">
58
+ Send reset link
59
+ </button>
60
+ <a class="text-muted-foreground hover:text-foreground text-center text-sm" href="/admin/login">
61
+ Back to sign in
62
+ </a>
63
+ </form>
64
+ ) : (
65
+ <div class="grid gap-4">
66
+ <p class="text-muted-foreground text-sm">
67
+ Password reset by email isn't set up for this site. Ask an administrator to help you get back in.
68
+ </p>
69
+ <a class="text-muted-foreground hover:text-foreground text-center text-sm" href="/admin/login">
70
+ Back to sign in
71
+ </a>
42
72
  </div>
43
73
  )
44
74
  }
45
- <form method="post" action="/api/cms/auth/forgot-password" class="grid gap-4">
46
- <div class="grid gap-2">
47
- <Label htmlFor="email">Email</Label>
48
- <Input id="email" name="email" type="email" placeholder="admin@example.com" required autoFocus />
49
- </div>
50
- <button class={buttonVariants({ size: "lg", className: "w-full" })} type="submit">Send reset link</button>
51
- <a class="text-muted-foreground hover:text-foreground text-center text-sm" href="/admin/login">
52
- Back to sign in
53
- </a>
54
- </form>
55
75
  </CardContent>
56
76
  </Card>
57
77
  </div>
@@ -0,0 +1,90 @@
1
+ ---
2
+ import "virtual:kide/admin-css";
3
+
4
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../../../admin/components/ui/card";
5
+ import { Input } from "../../../admin/components/ui/input";
6
+ import { Label } from "../../../admin/components/ui/label";
7
+ import { buttonVariants } from "../../../admin/components/ui/button";
8
+
9
+ export const prerender = false;
10
+
11
+ // Reached only mid-sign-in: Better Auth's short-lived two-factor cookie must be present.
12
+ if (!/(?:^|;\s*)(?:__Secure-)?kide\.two_factor=/.test(Astro.request.headers.get("cookie") ?? "")) {
13
+ return Astro.redirect("/admin/login?error=two-factor-expired");
14
+ }
15
+
16
+ const useBackupCode = Astro.url.searchParams.get("method") === "backup";
17
+ const ERROR_MESSAGES: Record<string, string> = {
18
+ missing: "Enter the code.",
19
+ invalid: useBackupCode ? "That backup code isn't valid." : "That code isn't valid. Check the time on your device.",
20
+ "rate-limited": "Too many attempts. Try again in a few minutes.",
21
+ };
22
+ const error = Astro.url.searchParams.get("error");
23
+ const errorMessage = error ? (ERROR_MESSAGES[error] ?? null) : null;
24
+ ---
25
+
26
+ <!doctype html>
27
+ <html lang="en">
28
+ <head>
29
+ <meta charset="utf-8" />
30
+ <meta name="viewport" content="width=device-width" />
31
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
32
+ <link rel="icon" href="/favicon.ico" />
33
+ <title>Two-factor authentication | Kide CMS</title>
34
+ </head>
35
+ <body class="bg-background text-foreground min-h-screen antialiased">
36
+ <div class="flex min-h-screen items-center justify-center px-4">
37
+ <div class="w-full max-w-sm space-y-6">
38
+ <h1 class="text-center text-xl font-semibold tracking-tight">Kide CMS</h1>
39
+ <Card>
40
+ <CardHeader>
41
+ <CardTitle>Two-factor authentication</CardTitle>
42
+ <CardDescription>
43
+ {
44
+ useBackupCode
45
+ ? "Enter one of the backup codes you saved when you set up two-factor authentication."
46
+ : "Enter the 6-digit code from your authenticator app."
47
+ }
48
+ </CardDescription>
49
+ </CardHeader>
50
+ <CardContent>
51
+ {
52
+ errorMessage && (
53
+ <div class="border-destructive/50 bg-destructive/10 text-destructive mb-4 rounded-lg border px-3 py-2 text-sm">
54
+ {errorMessage}
55
+ </div>
56
+ )
57
+ }
58
+ <form method="post" action="/api/cms/auth/login/verify" class="grid gap-4">
59
+ <input type="hidden" name="method" value={useBackupCode ? "backup" : "totp"} />
60
+ <div class="grid gap-2">
61
+ <Label htmlFor="code">{useBackupCode ? "Backup code" : "Code"}</Label>
62
+ <Input
63
+ id="code"
64
+ name="code"
65
+ type="text"
66
+ inputMode={useBackupCode ? "text" : "numeric"}
67
+ autoComplete="one-time-code"
68
+ pattern={useBackupCode ? undefined : "[0-9 ]*"}
69
+ required
70
+ autoFocus
71
+ />
72
+ </div>
73
+ <label class="text-muted-foreground flex items-center gap-2 text-sm">
74
+ <input type="checkbox" name="trustDevice" class="accent-primary size-4" />
75
+ Trust this device for 30 days
76
+ </label>
77
+ <button class={buttonVariants({ size: "lg", className: "w-full" })} type="submit">Verify</button>
78
+ <a
79
+ class="text-muted-foreground hover:text-foreground text-center text-sm"
80
+ href={useBackupCode ? "/admin/login/verify" : "/admin/login/verify?method=backup"}
81
+ >
82
+ {useBackupCode ? "Use your authenticator app instead" : "Use a backup code instead"}
83
+ </a>
84
+ </form>
85
+ </CardContent>
86
+ </Card>
87
+ </div>
88
+ </div>
89
+ </body>
90
+ </html>