diff --git a/src/pages/user.tsx b/src/pages/user.tsx index fe9d7308..29a24483 100644 --- a/src/pages/user.tsx +++ b/src/pages/user.tsx @@ -6,10 +6,10 @@ import { User } from "../db/types"; import { ACCOUNT_REGISTRATION, ALLOW_UNAUTHENTICATED, + BRANDING, HIDE_HISTORY, HTTP_ALLOWED, WEBROOT, - BRANDING, } from "../helpers/env"; import { userService } from "../services/user"; @@ -17,6 +17,150 @@ export { userService } from "../services/user"; export let FIRST_RUN = db.query("SELECT * FROM users").get() === null || false; +function ErrorBanner({ message }: { message: string }) { + return ( + + ); +} + +function LoginPage({ error, email = "" }: { error?: string; email?: string }) { + return ( + + <> +
+
+
+
+ {error ? : null} +
+ + +
+
+ {ACCOUNT_REGISTRATION ? ( + + Register + + ) : null} + +
+ +
+
+ + + ); +} + +function AccountPage({ email, error }: { email: string; error?: string }) { + return ( + + <> +
+
+
+
+ {error ? : null} +
+ + + +
+
+ +
+ +
+
+ + + ); +} + export const user = new Elysia() .use(userService) .get("/setup", ({ redirect }) => { @@ -208,67 +352,7 @@ export const user = new Elysia() auth.remove(); } - return ( - - <> -
-
-
-
-
- - -
-
- {ACCOUNT_REGISTRATION ? ( - - Register - - ) : null} - -
-
-
-
- - - ); + return ; }, { body: "signIn", cookie: "optionalSession" }, ) @@ -279,18 +363,14 @@ export const user = new Elysia() if (!existingUser) { set.status = 403; - return { - message: "Invalid credentials.", - }; + return ; } const validPassword = await Bun.password.verify(body.password, existingUser.password); if (!validPassword) { set.status = 403; - return { - message: "Invalid credentials.", - }; + return ; } const accessToken = await jwt.sign({ @@ -344,69 +424,7 @@ export const user = new Elysia() return redirect(`${WEBROOT}/`, 302); } - return ( - - <> -
-
-
-
-
- - - -
-
- -
-
-
-
- - - ); + return ; }, { auth: true, @@ -433,25 +451,24 @@ export const user = new Elysia() } const validPassword = await Bun.password.verify(body.password, existingUser.password); + const emailValue = body.email || existingUser.email; if (!validPassword) { set.status = 403; - return { - message: "Invalid credentials.", - }; + return ; } const fields = []; const values = []; if (body.email) { - const existingUser = await db + const existingEmailUser = await db .query("SELECT id FROM users WHERE email = ?") .as(User) .get(body.email); - if (existingUser && existingUser.id.toString() !== user.id) { + if (existingEmailUser && existingEmailUser.id.toString() !== user.id) { set.status = 409; - return { message: "Email already in use." }; + return ; } fields.push("email"); values.push(body.email);