diff --git a/README.md b/README.md index 2e98cca..f6741d4 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The foundation is in place: a public magazine site, a Supabase-backed editor all ## Foundation status - **Public site:** home, issue archive and issue detail, About, How it is made, Privacy, sitemap, robots, Open Graph image, and a custom not-found page. -- **Editor desk:** email magic links for emails on the editor list; Draft, Stories, Quarantine, Sources, Images, Issues, and admin-only Editors pages. +- **Editor desk:** Supabase email-and-password sign-in for accounts on the editor list; Draft, Stories, Quarantine, Sources, Images, Issues, and admin-only Editors pages. - **Supabase:** editors, editions, and runs tables; row-level security; public issues and private drafts buckets; vector extension. - **API:** health endpoint plus authenticated ingest and compile-callback stubs. The stubs only write run records. - **Automation:** CI checks, a three-times-daily GitHub Actions request, and a LaTeX reference compile workflow. diff --git a/app/desk/layout.tsx b/app/desk/layout.tsx index fa5488e..fd0422c 100644 --- a/app/desk/layout.tsx +++ b/app/desk/layout.tsx @@ -7,6 +7,8 @@ import { requireEditor } from "@/lib/auth/require-editor"; import { signOut } from "@/app/desk/actions"; import { Button } from "@/components/ui/button"; +export const dynamic = "force-dynamic"; + export default async function DeskLayout({ children, }: { diff --git a/app/login/actions.ts b/app/login/actions.ts index 8efea20..f2f4f31 100644 --- a/app/login/actions.ts +++ b/app/login/actions.ts @@ -1,56 +1,55 @@ "use server"; +import { redirect } from "next/navigation"; import { z } from "zod"; import { siteCopy } from "@/content/site"; -import { getPublicEnv } from "@/lib/env"; -import { createSupabaseAdminClient } from "@/lib/supabase/admin"; import { createSupabaseServerClient } from "@/lib/supabase/server"; export type LoginActionState = { message: string; - kind: "error" | "success" | ""; + kind: "error" | ""; }; -export async function sendMagicLink( +export async function signInEditor( _previousState: LoginActionState, formData: FormData, ): Promise { const parsedEmail = z.string().trim().email().safeParse(formData.get("email")); + const parsedPassword = z.string().min(1).safeParse(formData.get("password")); if (!parsedEmail.success) { return { message: siteCopy.login.invalidEmail, kind: "error" }; } + if (!parsedPassword.success) { + return { message: siteCopy.login.genericError, kind: "error" }; + } const email = parsedEmail.data.toLowerCase(); - const admin = createSupabaseAdminClient(); - const { data: editor, error: lookupError } = await admin - .from("editors") - .select("email") - .eq("email", email) - .maybeSingle(); + const supabase = await createSupabaseServerClient(); + const { data, error: signInError } = await supabase.auth.signInWithPassword({ + email, + password: parsedPassword.data, + }); - if (lookupError) { - return { message: siteCopy.login.checkInbox, kind: "success" }; - } - if (!editor) { - return { message: siteCopy.login.checkInbox, kind: "success" }; + if (signInError || !data.user) { + return { message: siteCopy.login.genericError, kind: "error" }; } - const { NEXT_PUBLIC_SITE_URL } = getPublicEnv(); - const callbackUrl = new URL("/auth/callback", NEXT_PUBLIC_SITE_URL); - callbackUrl.searchParams.set("next", "/desk"); + const signedInEmail = data.user.email?.toLowerCase(); + if (!signedInEmail || signedInEmail !== email) { + await supabase.auth.signOut(); + return { message: siteCopy.login.genericError, kind: "error" }; + } - const supabase = await createSupabaseServerClient(); - const { error } = await supabase.auth.signInWithOtp({ - email, - options: { - emailRedirectTo: callbackUrl.toString(), - shouldCreateUser: true, - }, - }); + const { data: editor, error: editorError } = await supabase + .from("editors") + .select("email") + .eq("email", signedInEmail) + .maybeSingle(); - if (error) { - return { message: siteCopy.login.checkInbox, kind: "success" }; + if (editorError || !editor) { + await supabase.auth.signOut(); + return { message: siteCopy.login.genericError, kind: "error" }; } - return { message: siteCopy.login.checkInbox, kind: "success" }; + redirect("/desk"); } diff --git a/app/login/login-form.tsx b/app/login/login-form.tsx index cecca21..d314538 100644 --- a/app/login/login-form.tsx +++ b/app/login/login-form.tsx @@ -2,7 +2,7 @@ import { useActionState } from "react"; import type { LoginActionState } from "@/app/login/actions"; -import { sendMagicLink } from "@/app/login/actions"; +import { signInEditor } from "@/app/login/actions"; import { siteCopy } from "@/content/site"; import { Button } from "@/components/ui/button"; @@ -10,7 +10,7 @@ const initialState: LoginActionState = { message: "", kind: "" }; export function LoginForm() { const [state, formAction, pending] = useActionState( - sendMagicLink, + signInEditor, initialState, ); @@ -31,9 +31,23 @@ export function LoginForm() { required type="email" /> + +

diff --git a/content/site.ts b/content/site.ts index 3908caf..cc17702 100644 --- a/content/site.ts +++ b/content/site.ts @@ -131,7 +131,7 @@ export const siteCopy = { "The site does not use advertising trackers or analytics cookies.", editorTitle: "Editor accounts", editorText: - "An editor's email address is used to send a sign-in link and to decide whether that person is on the editor list. It is not shown on public pages.", + "An editor's email address is used to sign in and to check whether that person is on the editor list. It is not shown on public pages.", storageTitle: "Issue files", storageText: "Published issue files may be publicly available. Draft files are kept in private storage for editors.", @@ -155,18 +155,17 @@ export const siteCopy = { eyebrow: "Editor access", title: "Sign in to the newsroom.", intro: - "Enter the email address on the editors list. We will send a sign-in link if it is approved.", + "Sign in with the university email and password set up by the newsroom admin. Only approved editors can enter.", email: "University email", placeholder: "name@undergrad.nfciet.edu.pk", - submit: "Send sign-in link", - sending: "Sending link…", - sent: "Check your inbox for a sign-in link.", + password: "Password", + submit: "Sign in", + signingIn: "Signing in…", invalidEmail: "Enter a valid email address.", notEditor: "This email isn't on the editors list. Ask the admin to add you.", genericError: - "We could not send the sign-in link. Check the address and try again.", + "Email or password is incorrect, or your account is not set up. Ask the newsroom admin for help.", back: "Back to the magazine", - checkInbox: "If the address is on the editors list, a sign-in link will arrive shortly.", }, desk: { title: "Editor desk", @@ -199,12 +198,14 @@ export const siteCopy = { issuesTitle: "Issues", issuesIntro: "View the editions stored for the magazine.", editorsTitle: "Editors", - editorsIntro: "Only add current NFC-IET students. Their email address will be used for sign-in.", + editorsIntro: + "Only add current NFC-IET students. Each editor also needs a Supabase Auth account with a password.", approve: "Approve", reject: "Not this one", edit: "Edit", restore: "Bring it back", addEditor: "Add editor", + savingEditor: "Saving…", removeEditor: "Remove", noStories: "No stories to review.", noRejected: "No rejected stories.", @@ -226,7 +227,8 @@ export const siteCopy = { }, editorName: "Student name", editorEmail: "University email", - editorAddHelp: "Add a current NFC-IET student to the editor allowlist.", + editorAddHelp: + "This adds the email to the allowlist. Then create that person's Supabase Auth account and password in the Supabase Dashboard.", editorCreated: "Editor added.", editorRemoved: "Editor removed.", editorDuplicate: "That email is already on the editor list.", diff --git a/docs/SETUP.md b/docs/SETUP.md index 929b11e..b5c86d7 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -83,14 +83,16 @@ This command replaces lib/supabase/types.ts with the schema generated from the l ## 3. Configure editor sign-in -In Supabase Dashboard, open Authentication URL Configuration. +In Supabase Dashboard, open Authentication → Sign In / Providers and make sure email-and-password sign-in is enabled. In Authentication settings, turn off **Allow new users to sign up**. Existing editor accounts can still sign in; admins create new accounts from the dashboard. -- Set the Site URL to the production app URL once Vercel is deployed. -- Add http://localhost:3000/** to the redirect URL allowlist. -- Add the production app URL followed by /auth/callback. -- Add a Vercel preview callback pattern only if editors need to sign in on preview deployments. +For every editor, do both steps: -The login action checks the submitted email against public.editors before it sends a magic link. The callback checks the editor row again after authentication. An account outside the allowlist is signed out and returned to the login page. +1. Add their lowercase email to `public.editors` (or use the admin-only Editors page). +2. In Authentication → Users, create a Supabase Auth user with the same email and a strong password. Mark the email confirmed if the dashboard offers that option. + +The email in `public.editors` is the allowlist; the Supabase Auth user and password prove who is signing in. Adding an email to the database alone does not create an Auth account. With email delivery disabled, password-reset emails will not arrive, so an admin must set a new password for an editor in Supabase Auth when needed. + +The app checks the password with Supabase Auth, then checks the signed-in user's email against `public.editors` under row-level security. A valid Auth account that is not on the editor list is signed out and denied access. Password sign-in does not need an email sender or redirect URL. ## 4. Fill local environment values @@ -149,7 +151,7 @@ If APP_URL is empty, the scheduled ingest workflow records a notice and exits wi - /about — department, supervisor, editors, correction and contribution information - /how-its-made — editorial process and source policy - /privacy — privacy note -- /login — email magic-link sign-in +- /login — Supabase email-and-password sign-in for allowlisted editors - /desk — draft preview shell - /desk/stories — sample stories; actions are temporary browser state - /desk/quarantine — sample rejected stories diff --git a/docs/SPEC.md b/docs/SPEC.md index 724bf31..c3af6da 100644 --- a/docs/SPEC.md +++ b/docs/SPEC.md @@ -267,7 +267,8 @@ Validate it with Zod. If it's invalid, retry once, then fall back to a simple de Source `og:image` is suggested but marked "needs review" (copyright: it's an official publication). 6. **Archive** — published editions. -Login: Supabase magic link, only emails in the `editors` table. +Login: Supabase email-and-password sign-in. Only Auth users whose email is in the +`editors` table may enter; admins provision each Auth account. --- @@ -357,7 +358,8 @@ Run typecheck + lint **once at the end of the phase**, then report. **Phase 4 — Dashboard** > Build the pages in section 10 (Draft can be a placeholder for now): Stories, Quarantine, -> Sources, Images, login with Supabase magic link and the editors allowlist. Approve/reject/restore +> Sources, Images, login with Supabase email and password and the editors allowlist. +> Approve/reject/restore > APIs must trigger a draft rebuild (stub for now). **Phase 5 — Draft builder + compile**