3 changed files with 21 additions and 6 deletions
+4 -3
View File
@@ -19,6 +19,7 @@ form.addEventListener("submit", (event) => {
event.preventDefault();
submit("/api/auth/login");
});
document
.querySelector("#signup")
.addEventListener("click", () => submit("/api/auth/signup"));
document.querySelector("#signup").addEventListener("click", () => {
const setupToken = form.elements.setupToken.value;
submit(setupToken ? "/api/auth/bootstrap" : "/api/auth/signup");
});
+7
View File
@@ -31,6 +31,13 @@
minlength="12"
name="password"
autocomplete="current-password" /></label
><label
>Initial admin setup token (first account only)
<input
class="field-input"
type="password"
name="setupToken"
autocomplete="off" /></label
><button class="primary-btn" type="submit">Log in</button
><button class="ghost-btn" type="button" id="signup">
Create account
+10 -3
View File
@@ -441,9 +441,16 @@ export function createApp({ db, root, env = process.env } = {}) {
.json({ ok: false, code: e.code, error: e.message });
}
});
app.get("/", (_q, res) =>
res.sendFile(path.join(root, "public", "landing.html")),
);
app.get("/", async (req, res, next) => {
try {
// Returning users should not be left on the sign-in page after a successful login.
if (await session(req)) return res.status(302).location("/app").end();
res.set("Cache-Control", "no-store, private");
res.sendFile(path.join(root, "public", "landing.html"));
} catch (error) {
next(error);
}
});
app.get("/app", requireAuth, (_q, res) =>
res.sendFile(path.join(root, "public", "index.html")),
);