create-thexjs-app 0.1.2 → 0.1.4
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/dist/index.js +43 -20
- package/package.json +2 -7
- package/templates/basic/src/components/Link.tsx +6 -12
- package/templates/basic/src/lib/auth.ts +17 -6
- package/templates/basic/src/pages/login.tsx +11 -4
- package/templates/basic/src/pages/placeholder.tsx +11 -2
- package/templates/blog/src/pages/index.tsx +4 -1
- package/templates/default/src/pages/index.tsx +1 -1
- package/templates/landing/src/components/code-block.tsx +104 -10
- package/templates/landing/src/layouts/main.tsx +48 -18
- package/templates/landing/src/pages/docs/_layout.tsx +26 -14
- package/templates/landing/src/pages/docs/api-routes.tsx +1 -1
- package/templates/landing/src/pages/docs/build-deploy.tsx +1 -1
- package/templates/landing/src/pages/docs/configuration.tsx +1 -1
- package/templates/landing/src/pages/docs/content-collections.tsx +1 -1
- package/templates/landing/src/pages/docs/data-layer.tsx +3 -3
- package/templates/landing/src/pages/docs/getting-started.tsx +4 -4
- package/templates/landing/src/pages/docs/installation.tsx +16 -20
- package/templates/landing/src/pages/docs/introduction.tsx +8 -11
- package/templates/landing/src/pages/docs/layouts.tsx +1 -1
- package/templates/landing/src/pages/docs/middleware.tsx +1 -1
- package/templates/landing/src/pages/docs/packages/cli.tsx +10 -7
- package/templates/landing/src/pages/docs/packages/core.tsx +9 -5
- package/templates/landing/src/pages/docs/packages/env.tsx +3 -3
- package/templates/landing/src/pages/docs/pages.tsx +1 -1
- package/templates/landing/src/pages/docs/routing.tsx +1 -1
- package/templates/landing/src/pages/docs/server-functions.tsx +60 -6
- package/templates/landing/src/pages/features.tsx +1 -1
- package/templates/landing/src/pages/index.tsx +91 -126
- package/templates/landing/src/styles/globals.css +81 -45
- package/templates/landing/tsconfig.json +6 -1
- package/templates/saas/src/api/auth/login.ts +31 -0
- package/templates/saas/src/lib/auth.ts +27 -6
- package/templates/saas/src/pages/dashboard/settings.tsx +8 -2
- package/templates/saas/src/pages/login.tsx +83 -10
- package/templates/landing/src/pages/contact.tsx +0 -95
|
@@ -1,7 +1,60 @@
|
|
|
1
|
+
import type { LoaderArgs, RouteProps } from "@thexjs/core";
|
|
1
2
|
import { LogIn } from "lucide-react";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../components/ui/button";
|
|
5
|
+
import { Input } from "../components/ui/input";
|
|
6
|
+
import { authenticate, setSessionCookie } from "../lib/auth";
|
|
2
7
|
import { cn } from "../lib/utils";
|
|
3
8
|
|
|
4
|
-
export
|
|
9
|
+
export async function loader({ request }: LoaderArgs) {
|
|
10
|
+
if (request.method === "POST") {
|
|
11
|
+
const formData = await request.formData();
|
|
12
|
+
const username = formData.get("email") as string | null;
|
|
13
|
+
const password = formData.get("password") as string | null;
|
|
14
|
+
const session = username && password ? authenticate(username, password) : null;
|
|
15
|
+
if (session) {
|
|
16
|
+
return new Response(null, {
|
|
17
|
+
status: 302,
|
|
18
|
+
headers: { Location: "/dashboard", "Set-Cookie": setSessionCookie(session.token) },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return { error: "Invalid credentials" };
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default function LoginPage({ loaderData }: RouteProps) {
|
|
27
|
+
const [error, setError] = useState((loaderData?.error as string) ?? "");
|
|
28
|
+
const [loading, setLoading] = useState(false);
|
|
29
|
+
|
|
30
|
+
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
setError("");
|
|
33
|
+
setLoading(true);
|
|
34
|
+
const form = e.currentTarget;
|
|
35
|
+
const data = {
|
|
36
|
+
email: (form.elements.namedItem("email") as HTMLInputElement).value,
|
|
37
|
+
password: (form.elements.namedItem("password") as HTMLInputElement).value,
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
const res = await fetch("/api/auth/login", {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { "Content-Type": "application/json" },
|
|
43
|
+
body: JSON.stringify(data),
|
|
44
|
+
});
|
|
45
|
+
if (res.ok) {
|
|
46
|
+
window.location.href = "/dashboard";
|
|
47
|
+
} else {
|
|
48
|
+
const err = (await res.json()) as { error?: string };
|
|
49
|
+
setError(err.error || "Login failed");
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
setError("Network error");
|
|
53
|
+
} finally {
|
|
54
|
+
setLoading(false);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
5
58
|
return (
|
|
6
59
|
<div className="flex min-h-[calc(100vh-4rem)] items-center justify-center px-4">
|
|
7
60
|
<div className="w-full max-w-sm">
|
|
@@ -15,7 +68,7 @@ export default function LoginPage() {
|
|
|
15
68
|
</h1>
|
|
16
69
|
<p className="mt-2 text-sm text-muted-foreground">Sign in to your account</p>
|
|
17
70
|
</div>
|
|
18
|
-
<form className="space-y-5">
|
|
71
|
+
<form method="POST" action="/login" onSubmit={handleSubmit} className="space-y-5">
|
|
19
72
|
<div>
|
|
20
73
|
<label
|
|
21
74
|
htmlFor="email"
|
|
@@ -23,11 +76,16 @@ export default function LoginPage() {
|
|
|
23
76
|
>
|
|
24
77
|
Email
|
|
25
78
|
</label>
|
|
26
|
-
<
|
|
79
|
+
<Input
|
|
27
80
|
id="email"
|
|
81
|
+
name="email"
|
|
28
82
|
type="email"
|
|
83
|
+
defaultValue="admin"
|
|
29
84
|
placeholder="you@example.com"
|
|
30
|
-
className=
|
|
85
|
+
className={cn(
|
|
86
|
+
"h-10 rounded-xl border-input bg-background px-4 py-2.5 text-sm text-foreground placeholder:text-muted-foreground",
|
|
87
|
+
)}
|
|
88
|
+
required
|
|
31
89
|
/>
|
|
32
90
|
</div>
|
|
33
91
|
<div>
|
|
@@ -37,20 +95,35 @@ export default function LoginPage() {
|
|
|
37
95
|
>
|
|
38
96
|
Password
|
|
39
97
|
</label>
|
|
40
|
-
<
|
|
98
|
+
<Input
|
|
41
99
|
id="password"
|
|
100
|
+
name="password"
|
|
42
101
|
type="password"
|
|
102
|
+
defaultValue="admin"
|
|
43
103
|
placeholder="••••••••"
|
|
44
|
-
className="
|
|
104
|
+
className="h-10 rounded-xl border-input bg-background px-4 py-2.5 text-sm text-foreground placeholder:text-muted-foreground"
|
|
105
|
+
required
|
|
45
106
|
/>
|
|
46
107
|
</div>
|
|
47
|
-
|
|
108
|
+
{error && (
|
|
109
|
+
<p id="login-error" className="text-sm text-destructive">
|
|
110
|
+
{error}
|
|
111
|
+
</p>
|
|
112
|
+
)}
|
|
113
|
+
<Button
|
|
48
114
|
type="submit"
|
|
49
|
-
|
|
115
|
+
disabled={loading}
|
|
116
|
+
className="h-10 w-full rounded-xl bg-primary px-4 py-2.5 text-sm font-semibold text-primary-foreground shadow-lg shadow-primary/20 transition-all hover:bg-primary/90 hover:shadow-xl hover:shadow-primary/25"
|
|
50
117
|
>
|
|
51
|
-
Sign in
|
|
52
|
-
</
|
|
118
|
+
{loading ? "Signing in..." : "Sign in"}
|
|
119
|
+
</Button>
|
|
53
120
|
</form>
|
|
121
|
+
<p className="mt-4 text-center text-xs text-muted-foreground">
|
|
122
|
+
Demo credentials: <code className="text-foreground">admin / admin</code>
|
|
123
|
+
</p>
|
|
124
|
+
<p className="mt-1 text-center text-[11px] text-muted-foreground">
|
|
125
|
+
Demo only — replace with real auth before shipping.
|
|
126
|
+
</p>
|
|
54
127
|
<p className="mt-6 text-center text-sm text-muted-foreground">
|
|
55
128
|
Don't have an account?{" "}
|
|
56
129
|
<a
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Mail, MapPin, Send } from "lucide-react";
|
|
2
|
-
|
|
3
|
-
export default function ContactPage() {
|
|
4
|
-
return (
|
|
5
|
-
<div className="mx-auto max-w-4xl px-6 py-20">
|
|
6
|
-
<div className="mx-auto max-w-2xl text-center">
|
|
7
|
-
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Contact</p>
|
|
8
|
-
<h1 className="mt-4 text-4xl font-bold tracking-tight sm:text-5xl">Get in touch</h1>
|
|
9
|
-
<p className="mt-4 text-lg text-muted-foreground">
|
|
10
|
-
Have a question or want to learn more? We'd love to hear from you.
|
|
11
|
-
</p>
|
|
12
|
-
</div>
|
|
13
|
-
|
|
14
|
-
<div className="mt-16 grid gap-12 sm:grid-cols-5">
|
|
15
|
-
<div className="space-y-8 sm:col-span-2">
|
|
16
|
-
<div>
|
|
17
|
-
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10 text-primary">
|
|
18
|
-
<Mail className="h-5 w-5" />
|
|
19
|
-
</div>
|
|
20
|
-
<h3 className="mt-4 text-sm font-semibold">Email</h3>
|
|
21
|
-
<p className="mt-1 text-sm text-muted-foreground">hello@x-framework.dev</p>
|
|
22
|
-
</div>
|
|
23
|
-
<div>
|
|
24
|
-
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10 text-primary">
|
|
25
|
-
<MapPin className="h-5 w-5" />
|
|
26
|
-
</div>
|
|
27
|
-
<h3 className="mt-4 text-sm font-semibold">Location</h3>
|
|
28
|
-
<p className="mt-1 text-sm text-muted-foreground">San Francisco, CA</p>
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
|
|
32
|
-
<form className="space-y-5 sm:col-span-3" method="POST" action="/contact">
|
|
33
|
-
<div className="grid gap-5 sm:grid-cols-2">
|
|
34
|
-
<div>
|
|
35
|
-
<label htmlFor="name" className="block text-sm font-medium mb-2">
|
|
36
|
-
Name
|
|
37
|
-
</label>
|
|
38
|
-
<input
|
|
39
|
-
id="name"
|
|
40
|
-
name="name"
|
|
41
|
-
required
|
|
42
|
-
className="w-full rounded-xl border border-input bg-card px-4 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
43
|
-
placeholder="Your name"
|
|
44
|
-
/>
|
|
45
|
-
</div>
|
|
46
|
-
<div>
|
|
47
|
-
<label htmlFor="email" className="block text-sm font-medium mb-2">
|
|
48
|
-
Email
|
|
49
|
-
</label>
|
|
50
|
-
<input
|
|
51
|
-
id="email"
|
|
52
|
-
name="email"
|
|
53
|
-
type="email"
|
|
54
|
-
required
|
|
55
|
-
className="w-full rounded-xl border border-input bg-card px-4 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
56
|
-
placeholder="you@example.com"
|
|
57
|
-
/>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
<div>
|
|
61
|
-
<label htmlFor="subject" className="block text-sm font-medium mb-2">
|
|
62
|
-
Subject
|
|
63
|
-
</label>
|
|
64
|
-
<input
|
|
65
|
-
id="subject"
|
|
66
|
-
name="subject"
|
|
67
|
-
required
|
|
68
|
-
className="w-full rounded-xl border border-input bg-card px-4 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
69
|
-
placeholder="How can we help?"
|
|
70
|
-
/>
|
|
71
|
-
</div>
|
|
72
|
-
<div>
|
|
73
|
-
<label htmlFor="message" className="block text-sm font-medium mb-2">
|
|
74
|
-
Message
|
|
75
|
-
</label>
|
|
76
|
-
<textarea
|
|
77
|
-
id="message"
|
|
78
|
-
name="message"
|
|
79
|
-
rows={5}
|
|
80
|
-
required
|
|
81
|
-
className="w-full resize-none rounded-xl border border-input bg-card px-4 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
|
|
82
|
-
placeholder="Tell us more..."
|
|
83
|
-
/>
|
|
84
|
-
</div>
|
|
85
|
-
<button
|
|
86
|
-
type="submit"
|
|
87
|
-
className="inline-flex h-11 items-center gap-2 rounded-xl bg-primary px-6 text-sm font-semibold text-primary-foreground shadow-lg shadow-primary/25 transition-all hover:bg-primary/90"
|
|
88
|
-
>
|
|
89
|
-
Send message <Send className="h-4 w-4" />
|
|
90
|
-
</button>
|
|
91
|
-
</form>
|
|
92
|
-
</div>
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
}
|