Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions app/desk/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}: {
Expand Down
57 changes: 28 additions & 29 deletions app/login/actions.ts
Original file line number Diff line number Diff line change
@@ -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<LoginActionState> {
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");
}
20 changes: 17 additions & 3 deletions app/login/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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";

const initialState: LoginActionState = { message: "", kind: "" };

export function LoginForm() {
const [state, formAction, pending] = useActionState(
sendMagicLink,
signInEditor,
initialState,
);

Expand All @@ -31,9 +31,23 @@ export function LoginForm() {
required
type="email"
/>
<label
className="mb-2 mt-5 block text-sm font-medium text-ink"
htmlFor="password"
>
{siteCopy.login.password}
</label>
<input
autoComplete="current-password"
className="min-h-12 w-full rounded border border-line bg-white px-4 text-base text-ink placeholder:text-muted focus-visible:border-leaf"
id="password"
name="password"
required
type="password"
/>
<div className="mt-5">
<Button type="submit" disabled={pending}>
{pending ? siteCopy.login.sending : siteCopy.login.submit}
{pending ? siteCopy.login.signingIn : siteCopy.login.submit}
</Button>
</div>
<p
Expand Down
2 changes: 1 addition & 1 deletion components/editor-management.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function AddEditorForm() {
</label>
<div className="flex items-end">
<Button type="submit" disabled={pending}>
{pending ? siteCopy.login.sending : siteCopy.desk.addEditor}
{pending ? siteCopy.desk.savingEditor : siteCopy.desk.addEditor}
</Button>
</div>
<p className="text-xs leading-5 text-muted md:col-span-3">
Expand Down
20 changes: 11 additions & 9 deletions content/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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",
Expand Down Expand Up @@ -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.",
Expand All @@ -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.",
Expand Down
16 changes: 9 additions & 7 deletions docs/SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions docs/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down Expand Up @@ -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**
Expand Down
Loading