From 1d7538379e291d1231b54b1bfb5f553597bed2b3 Mon Sep 17 00:00:00 2001 From: Reijjo Date: Wed, 1 Apr 2026 19:36:20 +0300 Subject: [PATCH 1/2] SOme frontend and couple of sql queries in the backend --- client/src/app/(auth)/layout.css | 27 +++++- .../_components/RegisterCredentials.tsx | 4 +- .../register/_components/RegisterEmail.tsx | 2 +- client/src/app/(auth)/verify/page.tsx | 22 +++++ client/src/lib/api/auth.ts | 9 +- rust-server/.cargo/config.toml | 7 ++ rust-server/src/db/queries.rs | 22 ++++- rust-server/src/features/auth/handlers.rs | 72 +++++++++++++-- rust-server/src/features/auth/queries.rs | 14 +++ rust-server/src/features/auth/routes.rs | 15 ++- rust-server/src/features/auth/types.rs | 21 +++++ rust-server/tests/api/common.rs | 92 ++++++++++++++++++- 12 files changed, 286 insertions(+), 21 deletions(-) create mode 100644 client/src/app/(auth)/verify/page.tsx create mode 100644 rust-server/.cargo/config.toml diff --git a/client/src/app/(auth)/layout.css b/client/src/app/(auth)/layout.css index f240a68..dd1246b 100644 --- a/client/src/app/(auth)/layout.css +++ b/client/src/app/(auth)/layout.css @@ -4,7 +4,8 @@ .auth-register, .auth-login, -.auth-forgot { +.auth-forgot, +.auth-verify { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0; @@ -16,6 +17,30 @@ } } +.auth-verify { + grid-template-columns: 1fr; + place-items: center; + background-image: radial-gradient( + at 50% 50%, + rgb(from var(--primary-500) r g b / 25%) 0, + transparent 80% + ); +} + +.container { + border: 1px solid rgb(from white r g b / 25%); + border-radius: 8px; + padding: 2rem; + display: flex; + flex-direction: column; + gap: 2rem; + text-align: center; + text-wrap: balance; + width: min(95%, 600px); + background: var(--primary-900); + box-shadow: var(--box-shadow-xl); +} + .form-container { width: 100%; height: 100%; diff --git a/client/src/app/(auth)/register/_components/RegisterCredentials.tsx b/client/src/app/(auth)/register/_components/RegisterCredentials.tsx index 17b7237..bdc9417 100644 --- a/client/src/app/(auth)/register/_components/RegisterCredentials.tsx +++ b/client/src/app/(auth)/register/_components/RegisterCredentials.tsx @@ -36,7 +36,7 @@ export default function RegisterCredentials({ label="username" name="username" id="username" - autoComplete="on" + autoComplete="username" type="text" placeholder="Username" className="auth-form-field" @@ -49,7 +49,7 @@ export default function RegisterCredentials({ name="password" id="password" type="password" - autoComplete="on" + autoComplete="new-password" placeholder="Password" className="auth-form-field" required diff --git a/client/src/app/(auth)/register/_components/RegisterEmail.tsx b/client/src/app/(auth)/register/_components/RegisterEmail.tsx index eef6e20..8a99ec1 100644 --- a/client/src/app/(auth)/register/_components/RegisterEmail.tsx +++ b/client/src/app/(auth)/register/_components/RegisterEmail.tsx @@ -39,7 +39,7 @@ export default function RegisterEmail({ id="email" type="email" placeholder="Enter your email" - autoComplete="on" + autoComplete="email" className="auth-form-field" required errors={formState.errors?.email ?? []} diff --git a/client/src/app/(auth)/verify/page.tsx b/client/src/app/(auth)/verify/page.tsx new file mode 100644 index 0000000..f4e5f77 --- /dev/null +++ b/client/src/app/(auth)/verify/page.tsx @@ -0,0 +1,22 @@ +"use client"; +import { useSearchParams } from "next/navigation"; + +export default function VerifyPage() { + const searchParams = useSearchParams(); + const token = searchParams.get("token"); + + // TODO: Implement actual verification logic by sending the token to the server for validation + + console.log("token:", token); + return ( +
+
+

Verify your email

+

+ A verification link has been sent to your email. Please check your + inbox and click the link to verify your account. +

+
+
+ ); +} diff --git a/client/src/lib/api/auth.ts b/client/src/lib/api/auth.ts index fdfa793..2ff7399 100644 --- a/client/src/lib/api/auth.ts +++ b/client/src/lib/api/auth.ts @@ -7,7 +7,7 @@ import type { RegisterUserData, } from "../types/auth"; -const AUTH_URL = `${config.BACKEND_URL}/auth`; +const AUTH_URL = `${config.BACKEND_URL}/api/auth`; // auth/available // GET @@ -86,3 +86,10 @@ export const loggingIn = async ( return { success: false, error: "Network error" }; } }; + +// auth/verify +// GET +// Verify email with token +// export const verifyAccount = async + +// TOdO: Implement verifyAccount function when needed diff --git a/rust-server/.cargo/config.toml b/rust-server/.cargo/config.toml new file mode 100644 index 0000000..ab4a21a --- /dev/null +++ b/rust-server/.cargo/config.toml @@ -0,0 +1,7 @@ +[env] +# Test configuration + +[test] +# Run tests serially to avoid database race conditions +# Each test truncates the database, so concurrent execution causes conflicts +test-threads = 1 \ No newline at end of file diff --git a/rust-server/src/db/queries.rs b/rust-server/src/db/queries.rs index a56474f..78103fa 100644 --- a/rust-server/src/db/queries.rs +++ b/rust-server/src/db/queries.rs @@ -1,4 +1,5 @@ -use sqlx::{PgPool, postgres::PgRow}; +use sqlx::{PgPool, Row, postgres::PgRow}; +use uuid::Uuid; use crate::errors::AppError; @@ -17,3 +18,22 @@ pub async fn find_user_by_username(db: &PgPool, username: &str) -> Result