Can you make it so a thread can be set to public so anyone can view?
Public threads
merged…
Osebotfable-5-150d ago
Plan: per-thread "public" switch so anyone with the link can read without signing in.
Today every thread already renders a 200 landing card to anonymous visitors (SignInGate) with just title + counts; the real posts need a session. I'll add an opt-in flag on the thread:
- Schema –
threads.public boolean default false not null(drizzle/0006 +db/schema.ts). Default private, so nothing existing changes. - Who can flip it – same people who can delete the thread: the thread creator or an owner of its workspace (
PATCH /api/threads/[id] { public }). Making a thread public exposes its posts, diffs and repo aliases to the internet, so I'm keeping it to that pair rather than every member; the owner can always revert. - Reading –
app/threads/[id]/page.tsx: anonymous + public → render the full read-only thread (no composer, no run/fork buttons, a "sign in to reply" note instead); anonymous + private → the existing sign-in gate. The SSE route/api/threads/[id]/eventsalso lets anonymous clients follow a public thread so live updates keep working. Writes are untouched. - UI – a small
public/privatetoggle in the.thread-metaline (samebutton.linkstyle as delete), with a "public" marker visible to everyone when it's on. OG/link preview unchanged (already public-safe). - Docs: README/architecture access-model lines;
npm run typecheck; mockup screenshot of the anonymous read-only view.
Osebotfable-5-150d ago
threadide@c315340Done — threads can now be made public. Pushed to thread/bae88cf4 (c315340). No PR opened; say the word and I'll open one.
What changed
threads.publicboolean, default false (drizzle/0006_public_threads.sql+ journal +db/schema.ts). Existing threads stay sign-in-only. Applies to prod on the next production build (scripts/migrate.tsruns beforenext build).- Who can flip it: the thread creator or a workspace owner — the same pair that can delete the thread, now one helper
canManageThread()inlib/session.ts(DELETE refactored onto it, behaviour unchanged). Not every member: going public exposes posts, diffs and repo aliases to the internet, and an owner can always revert. - API:
PATCH /api/threads/[id] { public: boolean }→{ id, public }; 403 with a readable message otherwise. - Reading:
app/threads/[id]/page.tsxloads the thread first. Anonymous + public → the full thread, read-only (no composer, no Ask Claude/Fork buttons, no delete; a "This thread is public. Sign in to reply." note in the dock). Anonymous + private → the existingSignInGate200 card as before. Signed-in behaviour is unchanged. - Live updates:
/api/threads/[id]/eventsnow usesrequireThreadReadable()— anonymous clients get the SSE stream on public threads, 401 on private ones (previously always required a session). - UI: new
components/thread-visibility.tsxin the.thread-metaline. Everyone sees the state (publicin bold, orsign-in only); managers get abutton.linktoggle. Going public is two-tap like delete ("make public to anyone with the link?" in red, auto-disarms after 4s); going back to sign-in-only is one tap. Errors from the API render inline. - Docs: README multiplayer paragraph +
lib/session.tsrow, architecture.md line.
Not changed, on purpose
- Writes of every kind still need a session + membership;
publicis read-only access. - Link previews / OG image were already public-safe (title, counts, excerpt) — untouched.
- Workspace pages and thread lists are still sign-in-only; this is per-thread by design, per the ask.
- Memory notes aren't exposed anywhere anonymous.
npm run typecheck passes. Screenshot attached is a static mockup (app needs Postgres + OAuth): owner view, armed state, and the anonymous read-only view.
One thing to be aware of: uploaded images in posts were already served from public Vercel Blob URLs, so making a thread public doesn't widen that.
Diff · 12 files
diff --git a/threadide/lib/session.ts b/threadide/lib/session.ts
--- a/threadide/lib/session.ts
+++ b/threadide/lib/session.ts
@@ -94,11 +95,34 @@ export async function requireWriter(workspaceId: string, user: CurrentUser) {
/** For read paths: 404 if the thread doesn't exist, no membership needed. */
export async function requireThreadExists(threadId: string) {
- const [t] = await db.select({ workspaceId: threads.workspaceId }).from(threads).where(eq(threads.id, threadId));
+ const [t] = await db.select({ workspaceId: threads.workspaceId, public: threads.public }).from(threads).where(eq(threads.id, threadId));
if (!t) throw new Forbidden(404, "not found");
return t;
}
+/**
+ * For read-only API paths that anonymous visitors may hit (the SSE stream): a signed-in user may
+ * read any thread, an anonymous one only a PUBLIC thread. 401 (not 404) when anonymous and private,
+ * so the client knows signing in would help.
+ */
+export async function requireThreadReadable(threadId: string) {
+ const [t, user] = await Promise.all([requireThreadExists(threadId), currentUser()]);
+ if (!user && !t.public) throw new Forbidden(401, "sign in required");
+ return { ...t, user };
+}
+
+/**
+ * Who may flip a thread's public flag or delete it: the thread's creator, or an owner of its
+ * workspace. Making a thread public exposes its posts, diffs and repo aliases to the internet,
+ * so this is deliberately narrower than "any member"; an owner can always revert it.
+ */
+export async function canManageThread(t: { createdBy: string | null; workspaceId: string | null }, user: CurrentUser) {
+ if (t.createdBy === user.id) return true;
+ if (!t.workspaceId) return false;
+ const m = await membership(t.workspaceId, user.id);
+ return m?.role === "owner";
+}
diff --git a/threadide/app/api/threads/[id]/route.ts b/threadide/app/api/threads/[id]/route.ts
--- a/threadide/app/api/threads/[id]/route.ts
+++ b/threadide/app/api/threads/[id]/route.ts
@@ -1,9 +1,32 @@
+const Patch = z.object({
+ // true = anyone with the link can read the thread without signing in. Writes are unaffected.
+ public: z.boolean(),
+});
+
+export const PATCH = guarded(async (req: Request, { params }: Params) => {
+ const user = await requireUserApi();
+ const { id } = await params;
+ const thread = await getThread(id);
+ if (!thread) throw new Forbidden(404, "not found");
+ if (!(await canManageThread(thread, user))) throw new Forbidden(403, "only the thread creator or a workspace owner can change who can read it");
+ const parsed = Patch.safeParse(await req.json());
+ if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
+ const t = await setThreadPublic(id, parsed.data.public);
+ if (!t) throw new Forbidden(404, "not found");
+ return NextResponse.json(t);
+});
@@ -13,8 +36,7 @@ export const DELETE = guarded(async (_req: Request, { params }: Params) => {
- const membership = thread.workspaceId ? await requireMember(thread.workspaceId, user) : null;
- if (thread.createdBy !== user.id && membership?.role !== "owner") throw new Forbidden(403, "only the thread creator or a workspace owner can delete");
+ if (!(await canManageThread(thread, user))) throw new Forbidden(403, "only the thread creator or a workspace owner can delete");
diff --git a/threadide/app/api/threads/[id]/events/route.ts b/threadide/app/api/threads/[id]/events/route.ts
--- a/threadide/app/api/threads/[id]/events/route.ts
+++ b/threadide/app/api/threads/[id]/events/route.ts
@@ -7,9 +7,8 @@
- // Read-only stream: any signed-in user may follow a thread.
- await requireUserApi();
- await requireThreadExists(id);
+ // Read-only stream: any signed-in user may follow a thread; anonymous visitors only a public one.
+ await requireThreadReadable(id);
diff --git a/threadide/app/threads/[id]/page.tsx b/threadide/app/threads/[id]/page.tsx
--- a/threadide/app/threads/[id]/page.tsx
+++ b/threadide/app/threads/[id]/page.tsx
@@ -35,27 +36,28 @@ export default async function ThreadPage({
- const user = await currentUser();
- if (!user) {
+ const [user, thread] = await Promise.all([currentUser(), getThread(id)]);
+ if (!thread) notFound();
+ if (!user && !thread.public) {
const t = await threadPreview(id);
if (!t) notFound();
return <SignInGate kicker=… title={t.title} description={describeThread(t)} next={`/threads/${id}`} />;
}
- const thread = await getThread(id);
- if (!thread) notFound();
thread.status = (await syncThreadMergeStatus(thread).catch(() => thread.status)) as typeof thread.status;
const ws = thread.workspace;
- const member = ws ? await membership(ws.id, user.id) : null;
- const canPost = ws ? member !== null || ws.open : true;
+ const member = ws && user ? await membership(ws.id, user.id) : null;
+ const canPost = user !== null && (ws ? member !== null || ws.open : true);
const canAskClaude = ws !== null && member !== null;
- const canDelete = thread.createdBy === user.id || member?.role === "owner";
+ // Delete and the public switch share one rule: thread creator or workspace owner.
+ const canManage = user !== null && (await canManageThread(thread, user));
@@ -90,7 +92,9 @@
<StatusBadge status={thread.status} /> · <ThreadLive threadId={thread.id} />
- {canDelete && <> · <DeleteThreadButton threadId={thread.id} /></>}
+ {" · "}
+ <ThreadVisibility threadId={thread.id} public={thread.public} canManage={canManage} />
+ {canManage && <> · <DeleteThreadButton threadId={thread.id} /></>}
@@ -125,6 +129,10 @@
<Composer threadId={thread.id} disabled={live} canAskClaude={canAskClaude} />
</>
+ ) : !user ? (
+ <p className="muted guest-note">
+ This thread is public. <Link href={`/signin?next=${encodeURIComponent(`/threads/${thread.id}`)}`}>Sign in</Link> to reply.
+ </p>
) : (
diff --git a/threadide/drizzle/0006_public_threads.sql b/threadide/drizzle/0006_public_threads.sql
new file mode 100644
--- /dev/null
+++ b/threadide/drizzle/0006_public_threads.sql
@@ -0,0 +1,4 @@
+-- Public threads: when true, anyone holding the link can read the thread (posts, diffs, live stream)
+-- without signing in. Writing still needs a session and the usual membership. Default keeps every
+-- existing thread sign-in-only.
+ALTER TABLE "threads" ADD COLUMN "public" boolean DEFAULT false NOT NULL;Pull requests:threadide #55
