@kidecms/core 0.31.0 → 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.
package/core/auth-engine.ts
CHANGED
|
@@ -251,6 +251,15 @@ const toGenericOAuth = (provider: AdminAuthSsoProviderConfig): GenericOAuthConfi
|
|
|
251
251
|
} as GenericOAuthConfig;
|
|
252
252
|
};
|
|
253
253
|
|
|
254
|
+
/**
|
|
255
|
+
* How a password reset link reaches the user: by email when an adapter is configured, in the
|
|
256
|
+
* dev server's terminal during development, otherwise not at all (the flow is then hidden).
|
|
257
|
+
*/
|
|
258
|
+
export const passwordResetDelivery = (): "email" | "console" | null => {
|
|
259
|
+
if (getEmail().isEmailConfigured()) return "email";
|
|
260
|
+
return process.env.NODE_ENV === "development" ? "console" : null;
|
|
261
|
+
};
|
|
262
|
+
|
|
254
263
|
const DEV_SECRET = "kide-development-secret-do-not-use-in-production";
|
|
255
264
|
let warnedDevSecret = false;
|
|
256
265
|
|
|
@@ -326,7 +335,13 @@ export const buildAdminAuthOptions = (config: CMSConfig, deps: AuthDeps = {}): B
|
|
|
326
335
|
sendResetPassword: async ({ user, token }) => {
|
|
327
336
|
const resetUrl = new URL("/admin/reset-password", baseURL);
|
|
328
337
|
resetUrl.searchParams.set("token", token);
|
|
329
|
-
|
|
338
|
+
const delivery = passwordResetDelivery();
|
|
339
|
+
if (delivery === "email") {
|
|
340
|
+
const sent = await getEmail().sendPasswordResetEmail?.(user.email, resetUrl.toString());
|
|
341
|
+
if (!sent) console.error(`[kide] The password reset email to ${user.email} could not be sent.`);
|
|
342
|
+
} else if (delivery === "console") {
|
|
343
|
+
console.info(`[kide] Email isn't configured — password reset link for ${user.email}:\n ${resetUrl}`);
|
|
344
|
+
}
|
|
330
345
|
},
|
|
331
346
|
},
|
|
332
347
|
session: {
|
package/core/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -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>
|
|
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
|
-
|
|
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>
|
package/routes/admin/login.astro
CHANGED
|
@@ -6,7 +6,7 @@ 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
8
|
import PasskeySignIn from "../../admin/components/PasskeySignIn";
|
|
9
|
-
import { getSsoProvider, resolveAdminAuth } from "../../core";
|
|
9
|
+
import { getSsoProvider, passwordResetDelivery, resolveAdminAuth } from "../../core";
|
|
10
10
|
import config from "virtual:kide/config";
|
|
11
11
|
|
|
12
12
|
export const prerender = false;
|
|
@@ -122,7 +122,7 @@ const hasSso = auth.ssoProviders.length > 0;
|
|
|
122
122
|
<div class="grid gap-2">
|
|
123
123
|
<div class="flex items-center justify-between gap-3">
|
|
124
124
|
<Label htmlFor="password">Password</Label>
|
|
125
|
-
{auth.password.forgotPassword && (
|
|
125
|
+
{auth.password.forgotPassword && passwordResetDelivery() && (
|
|
126
126
|
<a class="text-muted-foreground hover:text-foreground text-xs" href="/admin/forgot-password">
|
|
127
127
|
Forgot password?
|
|
128
128
|
</a>
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
getAdminAuth,
|
|
10
10
|
listSignInMethods,
|
|
11
11
|
loadAuthUser,
|
|
12
|
+
passwordResetDelivery,
|
|
12
13
|
resolveAdminAuth,
|
|
13
14
|
} from "../../../core";
|
|
14
15
|
import config from "virtual:kide/config";
|
|
@@ -19,6 +20,10 @@ export const prerender = false;
|
|
|
19
20
|
export const POST: APIRoute = async ({ request, clientAddress }) => {
|
|
20
21
|
const auth = resolveAdminAuth(config);
|
|
21
22
|
if (!auth.password.forgotPassword) return Response.json({ error: "Not found" }, { status: 404 });
|
|
23
|
+
// No way to deliver a link: the page explains that instead of pretending to send one.
|
|
24
|
+
if (!passwordResetDelivery()) {
|
|
25
|
+
return new Response(null, { status: 303, headers: { Location: "/admin/forgot-password" } });
|
|
26
|
+
}
|
|
22
27
|
|
|
23
28
|
const formData = await request.formData();
|
|
24
29
|
const email = String(formData.get("email") ?? "")
|