From b4e0689f84d743fd497d72519e820a27fadf191a Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Wed, 25 Nov 2026 22:39:02 +0100 Subject: [PATCH 1/7] feat: add example user to local db seeding script --- backend/src/db/seed/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/src/db/seed/index.ts b/backend/src/db/seed/index.ts index 533a346..80250d1 100644 --- a/backend/src/db/seed/index.ts +++ b/backend/src/db/seed/index.ts @@ -12,6 +12,7 @@ import { type InsertBook, } from "~/db/schema/books"; import { emptyToNull } from "~/utils/emptyToNull"; +import { auth } from "~/auth"; interface BookRow { bookId: string; @@ -159,6 +160,15 @@ if (booksToInsert.length > 0) { await insertBatch(booksToInsert, genresToInsert); } +// Add example user +await auth.api.signUpEmail({ + body: { + email: "user@example.com", + password: "password", + name: "Example User", + }, +}); + console.clear(); console.log("Seeding complete!"); process.exit(0); From adf5179656aa7f61825ad196acaea66ab5c1e4f7 Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Wed, 25 Nov 2026 22:39:15 +0100 Subject: [PATCH 2/7] feat: add button to log in as example user --- frontend/app/routes/login.tsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/frontend/app/routes/login.tsx b/frontend/app/routes/login.tsx index bad9864..02b96a5 100644 --- a/frontend/app/routes/login.tsx +++ b/frontend/app/routes/login.tsx @@ -23,6 +23,7 @@ import { Input } from "~/components/ui/Input"; import { Spinner } from "~/components/ui/Spinner"; import { toast } from "~/components/ui/Toast"; import { SocialLogins } from "~/components/SocialLogins/SocialLogins"; +import { Separator } from "~/components/ui/Separator"; const formSchema = z.object({ email: z.email("Enter a valid email address."), @@ -168,9 +169,23 @@ export default function LoginPage() { Sign up

- - Continue without an account - + + +

+ This will log you in as an example user with email + "user@example.com" and password "password". +

From d70aec8e74fd4602e485b9b14b0c6daa61bb07a3 Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Wed, 25 Nov 2026 23:19:23 +0100 Subject: [PATCH 3/7] feat: disallow changing example user in backend --- backend/src/auth/index.ts | 29 ++++- backend/src/db/seed/index.ts | 4 +- backend/tests/auth.test.ts | 50 ++++++++ .../settings/PasswordForm/PasswordForm.tsx | 109 ++++++++++-------- .../settings/ProfileForm/ProfileForm.tsx | 61 ++++++---- frontend/app/lib/constants.ts | 6 + frontend/app/routes/login.tsx | 5 +- frontend/app/routes/settings.test.tsx | 48 ++++++++ frontend/app/routes/settings.tsx | 24 +++- 9 files changed, 251 insertions(+), 85 deletions(-) create mode 100644 backend/tests/auth.test.ts create mode 100644 frontend/app/routes/settings.test.tsx diff --git a/backend/src/auth/index.ts b/backend/src/auth/index.ts index 4050d6f..44e8946 100644 --- a/backend/src/auth/index.ts +++ b/backend/src/auth/index.ts @@ -1,8 +1,23 @@ import { betterAuth } from "better-auth"; +import { + APIError, + createAuthMiddleware, + getSessionFromCtx, +} from "better-auth/api"; import { drizzleAdapter } from "@better-auth/drizzle-adapter/relations-v2"; import { db } from "~/db"; import * as schema from "~/db/schema"; +const EXAMPLE_USER_EMAIL = "user@example.com"; + +// Endpoints that would let one visitor change the example user for everyone else +const BLOCKED_FOR_EXAMPLE_USER = [ + "/update-user", + "/change-password", + "/change-email", + "/delete-user", +]; + const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", @@ -30,7 +45,19 @@ const auth = betterAuth({ clientSecret: process.env.DISCORD_CLIENT_SECRET ?? "", }, }, + hooks: { + before: createAuthMiddleware(async (ctx) => { + if (!BLOCKED_FOR_EXAMPLE_USER.includes(ctx.path)) return; + + const session = await getSessionFromCtx(ctx); + if (session?.user.email === EXAMPLE_USER_EMAIL) { + throw new APIError("FORBIDDEN", { + message: "The example user cannot be changed.", + }); + } + }), + }, trustedOrigins: [process.env.FRONTEND_URL ?? "http://localhost:5173"], }); -export { auth }; +export { auth, EXAMPLE_USER_EMAIL }; diff --git a/backend/src/db/seed/index.ts b/backend/src/db/seed/index.ts index 80250d1..44763f4 100644 --- a/backend/src/db/seed/index.ts +++ b/backend/src/db/seed/index.ts @@ -12,7 +12,7 @@ import { type InsertBook, } from "~/db/schema/books"; import { emptyToNull } from "~/utils/emptyToNull"; -import { auth } from "~/auth"; +import { auth, EXAMPLE_USER_EMAIL } from "~/auth"; interface BookRow { bookId: string; @@ -163,7 +163,7 @@ if (booksToInsert.length > 0) { // Add example user await auth.api.signUpEmail({ body: { - email: "user@example.com", + email: EXAMPLE_USER_EMAIL, password: "password", name: "Example User", }, diff --git a/backend/tests/auth.test.ts b/backend/tests/auth.test.ts new file mode 100644 index 0000000..b554ecc --- /dev/null +++ b/backend/tests/auth.test.ts @@ -0,0 +1,50 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import { auth, EXAMPLE_USER_EMAIL } from "~/auth"; + +const PASSWORD = "password"; + +// Signs up a user and returns headers that carry its session cookie. +async function signUp(email: string) { + const { headers } = await auth.api.signUpEmail({ + body: { email, password: PASSWORD, name: "Original name" }, + returnHeaders: true, + }); + return new Headers({ cookie: headers.get("set-cookie") ?? "" }); +} + +describe("example user", () => { + let headers: Headers; + + beforeAll(async () => { + headers = await signUp(EXAMPLE_USER_EMAIL); + }); + + it("cannot change name or bio", async () => { + await expect( + auth.api.updateUser({ headers, body: { name: "Changed", bio: "Hi" } }), + ).rejects.toMatchObject({ statusCode: 403 }); + + const session = await auth.api.getSession({ headers }); + expect(session?.user.name).toBe("Original name"); + }); + + it("cannot change password", async () => { + await expect( + auth.api.changePassword({ + headers, + body: { currentPassword: PASSWORD, newPassword: "new-password" }, + }), + ).rejects.toMatchObject({ statusCode: 403 }); + }); +}); + +describe("other users", () => { + it("can still change name and bio", async () => { + const headers = await signUp("someone@example.com"); + + await auth.api.updateUser({ headers, body: { name: "Changed" } }); + + const session = await auth.api.getSession({ headers }); + expect(session?.user.name).toBe("Changed"); + }); +}); diff --git a/frontend/app/components/settings/PasswordForm/PasswordForm.tsx b/frontend/app/components/settings/PasswordForm/PasswordForm.tsx index bacf080..b47a078 100644 --- a/frontend/app/components/settings/PasswordForm/PasswordForm.tsx +++ b/frontend/app/components/settings/PasswordForm/PasswordForm.tsx @@ -26,7 +26,7 @@ const passwordFormSchema = z.object({ confirmPassword: z.string().min(1, "Confirm your new password."), }); -function PasswordForm() { +function PasswordForm({ disabled = false }: { disabled?: boolean }) { const [serverError, setServerError] = useState(null); const form = useAppForm({ @@ -76,62 +76,69 @@ function PasswordForm() {
{ e.preventDefault(); void form.handleSubmit(); }} > - - - - {(field) => ( - - )} - - - {(field) => ( - - )} - - { - if (value !== fieldApi.form.getFieldValue("newPassword")) { - return { message: "Passwords do not match." }; - } - return undefined; - }, - }} - > - {(field) => ( - - )} - - {serverError} - - - - - Change password - - + {/* Disabling the fieldset disables every input and button in it */} +
+ + + + {(field) => ( + + )} + + + {(field) => ( + + )} + + { + if ( + value !== fieldApi.form.getFieldValue("newPassword") + ) { + return { message: "Passwords do not match." }; + } + return undefined; + }, + }} + > + {(field) => ( + + )} + + {serverError} + + + + + {disabled ? "Unavailable for example user" : "Change password"} + + +
diff --git a/frontend/app/components/settings/ProfileForm/ProfileForm.tsx b/frontend/app/components/settings/ProfileForm/ProfileForm.tsx index 49db23a..641be5c 100644 --- a/frontend/app/components/settings/ProfileForm/ProfileForm.tsx +++ b/frontend/app/components/settings/ProfileForm/ProfileForm.tsx @@ -23,7 +23,13 @@ const profileFormSchema = z.object({ .max(MAX_BIO_LENGTH, `Bio must be at most ${MAX_BIO_LENGTH} characters.`), }); -function ProfileForm({ name, bio }: { name: string; bio: string }) { +interface ProfileFormProps { + name: string; + bio: string; + disabled?: boolean; +} + +function ProfileForm({ name, bio, disabled = false }: ProfileFormProps) { const [serverError, setServerError] = useState(null); const form = useAppForm({ @@ -70,36 +76,41 @@ function ProfileForm({ name, bio }: { name: string; bio: string }) {
{ e.preventDefault(); void form.handleSubmit(); }} > - - - - {(field) => ( - - )} - - - {(field) => ( - - )} - - {serverError} - - - - - Save profile - - + {/* Disabling the fieldset disables every input and button in it */} +
+ + + + {(field) => ( + + )} + + + {(field) => ( + + )} + + {serverError} + + + + + {disabled ? "Unavailable for example user" : "Save profile"} + + +
diff --git a/frontend/app/lib/constants.ts b/frontend/app/lib/constants.ts index 34a0862..9601f5f 100644 --- a/frontend/app/lib/constants.ts +++ b/frontend/app/lib/constants.ts @@ -1,6 +1,10 @@ // Make sure this matches the minimum password length set in backend/src/auth/index.ts const MIN_PASSWORD_LENGTH = 8; +// Make sure this matches EXAMPLE_USER_EMAIL in backend/src/auth/index.ts +const EXAMPLE_USER_EMAIL = "user@example.com"; +const EXAMPLE_USER_PASSWORD = "password"; + // Default number of books shown on a page const BOOK_PAGE_LIMIT = 12; @@ -23,6 +27,8 @@ const MAX_REVIEW_COMMENT_LENGTH = 2000; export { MIN_PASSWORD_LENGTH, + EXAMPLE_USER_EMAIL, + EXAMPLE_USER_PASSWORD, BOOK_PAGE_LIMIT, FAVORITE_BOOKS_PAGE_LIMIT, MIN_RATINGS, diff --git a/frontend/app/routes/login.tsx b/frontend/app/routes/login.tsx index 02b96a5..4668fdf 100644 --- a/frontend/app/routes/login.tsx +++ b/frontend/app/routes/login.tsx @@ -24,6 +24,7 @@ import { Spinner } from "~/components/ui/Spinner"; import { toast } from "~/components/ui/Toast"; import { SocialLogins } from "~/components/SocialLogins/SocialLogins"; import { Separator } from "~/components/ui/Separator"; +import { EXAMPLE_USER_EMAIL, EXAMPLE_USER_PASSWORD } from "~/lib/constants"; const formSchema = z.object({ email: z.email("Enter a valid email address."), @@ -175,8 +176,8 @@ export default function LoginPage() { type="submit" onClick={(e) => { e.preventDefault(); - form.setFieldValue("email", "user@example.com"); - form.setFieldValue("password", "password"); + form.setFieldValue("email", EXAMPLE_USER_EMAIL); + form.setFieldValue("password", EXAMPLE_USER_PASSWORD); void form.handleSubmit(); }} > diff --git a/frontend/app/routes/settings.test.tsx b/frontend/app/routes/settings.test.tsx new file mode 100644 index 0000000..a20070e --- /dev/null +++ b/frontend/app/routes/settings.test.tsx @@ -0,0 +1,48 @@ +import { describe, expect, it, vi } from "vitest"; +import { screen } from "@testing-library/react"; +import { authClient } from "~/api/auth"; +import SettingsPage from "~/routes/settings"; +import { EXAMPLE_USER_EMAIL } from "~/lib/constants"; +import { renderRoutes } from "~/test/renderRoutes"; +import { loggedIn } from "~/test/session"; + +vi.mock("~/api/auth", () => ({ + authClient: { useSession: vi.fn(() => loggedIn) }, +})); + +const routes = [{ path: "/settings", Component: SettingsPage }]; + +function renderSettings() { + renderRoutes(routes, { initialEntries: ["/settings"] }); +} + +describe("SettingsPage", () => { + it("lets a normal user edit the forms", () => { + renderSettings(); + + expect(screen.getByLabelText("Name")).toBeEnabled(); + expect(screen.getByLabelText("Current password")).toBeEnabled(); + expect(screen.getByRole("button", { name: "Save profile" })).toBeEnabled(); + expect( + screen.getByRole("button", { name: "Change password" }), + ).toBeEnabled(); + }); + + it("disables the forms for the example user", () => { + const exampleUser = structuredClone(loggedIn); + if (exampleUser.data) exampleUser.data.user.email = EXAMPLE_USER_EMAIL; + vi.mocked(authClient.useSession).mockReturnValue(exampleUser); + + renderSettings(); + + expect(screen.getByText(/logged in as the example user/)).toBeVisible(); + expect(screen.getByLabelText("Name")).toBeDisabled(); + expect(screen.getByLabelText("Bio")).toBeDisabled(); + expect(screen.getByLabelText("Current password")).toBeDisabled(); + const buttons = screen.getAllByRole("button", { + name: "Unavailable for example user", + }); + expect(buttons).toHaveLength(2); + for (const button of buttons) expect(button).toBeDisabled(); + }); +}); diff --git a/frontend/app/routes/settings.tsx b/frontend/app/routes/settings.tsx index f72f296..9339479 100644 --- a/frontend/app/routes/settings.tsx +++ b/frontend/app/routes/settings.tsx @@ -5,6 +5,8 @@ import { Skeleton } from "~/components/ui/Skeleton"; import { ProfileForm } from "~/components/settings/ProfileForm/ProfileForm"; import { PasswordForm } from "~/components/settings/PasswordForm/PasswordForm"; import { ArrowLeftIcon } from "lucide-react"; +import { EXAMPLE_USER_EMAIL } from "~/lib/constants"; +import { cn } from "cn"; export function meta() { return [{ title: "Settings | Readr" }]; @@ -25,6 +27,9 @@ export default function SettingsPage() { return ; } + // Everyone shares the example user, so the server blocks changes to it + const isExampleUser = session.user.email === EXAMPLE_USER_EMAIL; + return (
Back to profile -

- Update your profile information and change your password. +

+ {isExampleUser + ? "You are logged in as the example user, which everyone shares, so its profile and password cannot be changed." + : "Update your profile information and change your password."}

- - + +
); From ecbedf89621f2e9001378165deacab1be8154d8e Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Wed, 25 Nov 2026 23:26:50 +0100 Subject: [PATCH 4/7] feat: add more info to example user settings --- frontend/app/routes/settings.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/routes/settings.tsx b/frontend/app/routes/settings.tsx index 9339479..28ea617 100644 --- a/frontend/app/routes/settings.tsx +++ b/frontend/app/routes/settings.tsx @@ -66,7 +66,7 @@ export default function SettingsPage() { )} > {isExampleUser - ? "You are logged in as the example user, which everyone shares, so its profile and password cannot be changed." + ? "You are logged in as the example user, which everyone shares, so its profile and password cannot be changed. Please create your own account to change your profile and password." : "Update your profile information and change your password."}

Date: Thu, 26 Nov 2026 15:50:47 +0100 Subject: [PATCH 5/7] feat: change to secure password for example user --- README.md | 12 ++++++++++++ backend/src/auth/index.ts | 3 ++- backend/src/db/seed/index.ts | 4 ++-- backend/tests/auth.test.ts | 11 ++++++----- frontend/app/lib/constants.ts | 4 ++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e4c76e8..79e02c5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,18 @@ Anyone can discover books without signing in. Registered users can also save fav - **Use the application comfortably:** Readr supports keyboard use, responsive layouts, light and dark themes, and accessible feedback. +We provide an example user that anyone can use. This is also helpful for evaluators when reviewing the project. +Just use the "Login as example user" button on the login screen. You can also take a look at the credentials below if you want to log in manually. + +
+ +Example user credentials + +Email: `user@example.com` +Password: `msQBPuJzExgnWGwT` + +
+ ## Getting started In order to get started with the project, check the READMEs for the respective part of the project: diff --git a/backend/src/auth/index.ts b/backend/src/auth/index.ts index 44e8946..c7f4f20 100644 --- a/backend/src/auth/index.ts +++ b/backend/src/auth/index.ts @@ -9,6 +9,7 @@ import { db } from "~/db"; import * as schema from "~/db/schema"; const EXAMPLE_USER_EMAIL = "user@example.com"; +const EXAMPLE_USER_PASSWORD = "msQBPuJzExgnWGwT"; // Endpoints that would let one visitor change the example user for everyone else const BLOCKED_FOR_EXAMPLE_USER = [ @@ -60,4 +61,4 @@ const auth = betterAuth({ trustedOrigins: [process.env.FRONTEND_URL ?? "http://localhost:5173"], }); -export { auth, EXAMPLE_USER_EMAIL }; +export { auth, EXAMPLE_USER_EMAIL, EXAMPLE_USER_PASSWORD }; diff --git a/backend/src/db/seed/index.ts b/backend/src/db/seed/index.ts index 44763f4..c32d041 100644 --- a/backend/src/db/seed/index.ts +++ b/backend/src/db/seed/index.ts @@ -12,7 +12,7 @@ import { type InsertBook, } from "~/db/schema/books"; import { emptyToNull } from "~/utils/emptyToNull"; -import { auth, EXAMPLE_USER_EMAIL } from "~/auth"; +import { auth, EXAMPLE_USER_EMAIL, EXAMPLE_USER_PASSWORD } from "~/auth"; interface BookRow { bookId: string; @@ -164,7 +164,7 @@ if (booksToInsert.length > 0) { await auth.api.signUpEmail({ body: { email: EXAMPLE_USER_EMAIL, - password: "password", + password: EXAMPLE_USER_PASSWORD, name: "Example User", }, }); diff --git a/backend/tests/auth.test.ts b/backend/tests/auth.test.ts index b554ecc..8a9ae41 100644 --- a/backend/tests/auth.test.ts +++ b/backend/tests/auth.test.ts @@ -1,12 +1,10 @@ import { beforeAll, describe, expect, it } from "vitest"; -import { auth, EXAMPLE_USER_EMAIL } from "~/auth"; - -const PASSWORD = "password"; +import { auth, EXAMPLE_USER_EMAIL, EXAMPLE_USER_PASSWORD } from "~/auth"; // Signs up a user and returns headers that carry its session cookie. async function signUp(email: string) { const { headers } = await auth.api.signUpEmail({ - body: { email, password: PASSWORD, name: "Original name" }, + body: { email, password: EXAMPLE_USER_PASSWORD, name: "Original name" }, returnHeaders: true, }); return new Headers({ cookie: headers.get("set-cookie") ?? "" }); @@ -32,7 +30,10 @@ describe("example user", () => { await expect( auth.api.changePassword({ headers, - body: { currentPassword: PASSWORD, newPassword: "new-password" }, + body: { + currentPassword: EXAMPLE_USER_PASSWORD, + newPassword: "new-password", + }, }), ).rejects.toMatchObject({ statusCode: 403 }); }); diff --git a/frontend/app/lib/constants.ts b/frontend/app/lib/constants.ts index 9601f5f..ffe5318 100644 --- a/frontend/app/lib/constants.ts +++ b/frontend/app/lib/constants.ts @@ -1,9 +1,9 @@ // Make sure this matches the minimum password length set in backend/src/auth/index.ts const MIN_PASSWORD_LENGTH = 8; -// Make sure this matches EXAMPLE_USER_EMAIL in backend/src/auth/index.ts +// Make sure this matches in backend/src/auth/index.ts const EXAMPLE_USER_EMAIL = "user@example.com"; -const EXAMPLE_USER_PASSWORD = "password"; +const EXAMPLE_USER_PASSWORD = "msQBPuJzExgnWGwT"; // Default number of books shown on a page const BOOK_PAGE_LIMIT = 12; From 6145205adf31dc2e634097d70940763b2b83b146 Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Thu, 26 Nov 2026 15:54:53 +0100 Subject: [PATCH 6/7] feat(login): remove unnecessary info text, bring back continue button --- frontend/app/routes/login.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/app/routes/login.tsx b/frontend/app/routes/login.tsx index 4668fdf..a35d9f2 100644 --- a/frontend/app/routes/login.tsx +++ b/frontend/app/routes/login.tsx @@ -170,6 +170,12 @@ export default function LoginPage() { Sign up

+ + Continue without an account + -

- This will log you in as an example user with email - "user@example.com" and password "password". -

From 970357da422f526fbb003820d09eaef6a62f31b2 Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Thu, 26 Nov 2026 16:02:56 +0100 Subject: [PATCH 7/7] docs: add newline between email and password of example user --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 79e02c5..423605e 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Just use the "Login as example user" button on the login screen. You can also ta Example user credentials Email: `user@example.com` + Password: `msQBPuJzExgnWGwT`