Skip to content

Commit 9ec79e1

Browse files
committed
refactor: update routes for Bootstrap component APIs
- Home: simplify to pass Layout only LoginStatus (h1 moved to component) - Auth (login): centered layout, remove FormSection wrapper - Auth (magic link): centered layout with form-label and form-control - Auth (GitHub OAuth): default callbackURL to /profile - Profile: use outline-secondary back link, outline-danger logout - Admin: cleaned up commented query params, Bootstrap button styles
1 parent 1f2d9f1 commit 9ec79e1

4 files changed

Lines changed: 49 additions & 56 deletions

File tree

src/app/routes/admin.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,9 @@ export default new Hono()
99
.get("/admin", async (c) => {
1010
const auth = getAuthFromContext(c);
1111
const users = await auth.api.listUsers({
12-
query: {
13-
query: {
14-
// searchValue: "some name",
15-
// searchField: "name",
16-
// searchOperator: "contains",
17-
// limit: 100,
18-
// offset: 100,
19-
// sortBy: "name",
20-
// sortDirection: "desc",
21-
// filterField: "email",
22-
// filterValue: "hello@example.com",
23-
// filterOperator: "eq",
24-
},
25-
},
12+
query: { query: {} },
2613
headers: c.req.raw.headers,
2714
});
28-
console.log(users);
2915

3016
const error = c.req.query("error");
3117
const success = c.req.query("success");
@@ -34,8 +20,10 @@ export default new Hono()
3420
Layout({
3521
title: "Admin",
3622
children: html`
37-
<h1>Admin</h1>
38-
<a href="/">Back to Home</a>
23+
<h1 class="h3 mb-3 fw-semibold">Admin</h1>
24+
<a href="/" class="btn btn-outline-secondary btn-sm mb-3"
25+
>← Back to Home</a
26+
>
3927
4028
${Message({ error, success })}
4129
${UsersList({ users: users.users, total: users.total })}
@@ -50,10 +38,7 @@ export default new Hono()
5038

5139
try {
5240
await auth.api.setRole({
53-
body: {
54-
userId,
55-
role,
56-
},
41+
body: { userId, role },
5742
headers: c.req.raw.headers,
5843
});
5944

src/app/routes/auth.js

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Hono } from "hono";
22
import { html } from "hono/html";
33
import { Layout, Navigation } from "../components/layout.js";
4-
import { Message, FormSection } from "../components/common.js";
4+
import { Message } from "../components/common.js";
55
import { GitHubButton, MagicLinkButton } from "../components/login.js";
66
import { getAuthFromContext } from "../utils/auth.js";
77
import { logout } from "../handlers/logout.js";
@@ -17,14 +17,18 @@ function showLogin(c) {
1717
Layout({
1818
title: "Sign In",
1919
children: html`
20-
<h1>Sign In</h1>
21-
${Navigation({ back: { href: "/", text: "Back to Home" } })}
22-
${Message({ error, success })}
23-
${FormSection({
24-
children: html`
25-
${MagicLinkButton({ callbackURL })} ${GitHubButton({ callbackURL })}
26-
`,
27-
})}
20+
<div class="row justify-content-center">
21+
<div class="col-md-8 col-lg-6">
22+
<h1 class="h3 mb-3 fw-semibold">Sign In</h1>
23+
${Navigation({ back: { href: "/", text: "Back to Home" } })}
24+
<hr class="my-3" />
25+
${Message({ error, success })}
26+
<div class="row g-3">
27+
<div class="col-sm-6">${GitHubButton({ callbackURL })}</div>
28+
<div class="col-sm-6">${MagicLinkButton({ callbackURL })}</div>
29+
</div>
30+
</div>
31+
</div>
2832
`,
2933
}),
3034
);
@@ -37,28 +41,34 @@ function showMagicLinkForm(c) {
3741
Layout({
3842
title: "Magic Link Login",
3943
children: html`
40-
<h1>Magic Link Login</h1>
41-
${Navigation({ back: { href: "/login", text: "Back to Login" } })}
42-
${Message({
43-
error: c.req.query("error"),
44-
success: c.req.query("success"),
45-
})}
46-
${FormSection({
47-
children: html`
44+
<div class="row justify-content-center">
45+
<div class="col-md-6 col-lg-5">
46+
<h1 class="h3 mb-3 fw-semibold">Sign In</h1>
47+
${Navigation({ back: { href: "/login", text: "Back to Login" } })}
48+
<hr class="my-3" />
49+
${Message({
50+
error: c.req.query("error"),
51+
success: c.req.query("success"),
52+
})}
4853
<form method="post" action="/login/magic-link">
4954
<input type="hidden" name="callbackURL" value="${callbackURL}" />
50-
<fieldset>
55+
<div class="mb-3">
56+
<label for="email" class="form-label">Email address</label>
5157
<input
5258
type="email"
59+
class="form-control"
60+
id="email"
5361
name="email"
54-
placeholder="Enter your email"
62+
placeholder="you@example.com"
5563
required
5664
/>
57-
</fieldset>
58-
<button type="submit">Send Magic Link</button>
65+
</div>
66+
<button type="submit" class="btn btn-cb-primary w-100">
67+
Send magic link
68+
</button>
5969
</form>
60-
`,
61-
})}
70+
</div>
71+
</div>
6272
`,
6373
}),
6474
);
@@ -85,7 +95,7 @@ async function sendMagicLink(c) {
8595
async function startGitHubOAuth(c) {
8696
const auth = getAuthFromContext(c);
8797
const body = await c.req.parseBody();
88-
const { callbackURL } = body;
98+
const callbackURL = body.callbackURL || "/";
8999

90100
const data = await auth.api.signInSocial({
91101
body: { provider: "github", callbackURL },

src/app/routes/home.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ export default new Hono().get("/", async (c) => {
77
const user = c.get("user");
88
return c.html(
99
Layout({
10-
title: "Auth Demo",
11-
children: html`
12-
<h1>codebar authentication</h1>
13-
${LoginStatus({ user })}
14-
`,
10+
title: "Home",
11+
children: html`${LoginStatus({ user })}`,
1512
}),
1613
);
1714
});

src/app/routes/profile.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Message } from "../components/common.js";
55
import { UserInfo } from "../components/profile.js";
66

77
export default new Hono().get("/profile", async (c) => {
8-
// Profile page
98
const user = c.get("user");
109
if (!user) return c.redirect("/login?error=no+session");
1110

@@ -16,14 +15,16 @@ export default new Hono().get("/profile", async (c) => {
1615
Layout({
1716
title: "Profile",
1817
children: html`
19-
<h1>Profile</h1>
18+
<h1 class="h3 mb-3 fw-semibold">Profile</h1>
2019
2120
${Message({ error, success })} ${UserInfo({ user })}
2221
23-
<form method="post" action="/logout">
24-
<button type="submit">Logout</button>
25-
</form>
26-
<a href="/">Back to Home</a>
22+
<div class="mt-3 d-flex gap-2">
23+
<a href="/" class="btn btn-outline-secondary">← Back to Home</a>
24+
<form method="post" action="/logout" class="d-inline">
25+
<button type="submit" class="btn btn-outline-danger">Logout</button>
26+
</form>
27+
</div>
2728
`,
2829
}),
2930
);

0 commit comments

Comments
 (0)