Skip to content
Open
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
16 changes: 14 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
# Optional for the public site. Copy this file to .env at the repository root.
# All workspace commands load root .env files; process variables take precedence.

# Neon PostgreSQL connection string; leave blank until database features are added.
# Neon runtime connection string; required for the forum, optional for Astro.
# Example: postgresql://USER:PASSWORD@HOST/DATABASE?sslmode=require
DATABASE_URL=

# Shared auth factories are ready for future use; no auth routes are mounted.
# Direct connections for migration and moderator commands. Never used interchangeably.
DEV_DATABASE_URL=
PROD_DATABASE_URL=

# Authentication is hosted by the Next.js forum app.
# Generate a secret with: openssl rand -base64 32
BETTER_AUTH_SECRET=
# Production on Vercel: https://forum.manipalosf.org (no /forum suffix).
BETTER_AUTH_URL=http://localhost:3000

# Cross-app links. Development defaults to localhost ports 3000 and 4321.
# Defaults to https://forum.manipalosf.org/ in production; override if needed.
PUBLIC_FORUM_URL=
# Defaults to https://manipalosf.org in production.
PUBLIC_SITE_URL=

# Required for forum signup, email verification, and password recovery.
# Resend API key and a sender address on your verified domain.
# Local email previews do not need these values.
RESEND_API_KEY=
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm test
- run: pnpm db:check
- run: pnpm build
- run: node scripts/prepare-vercel.mjs
- run: node scripts/verify-vercel.mjs
- name: Prepare and verify Astro service output
run: |
node scripts/prepare-vercel.mjs
node scripts/verify-vercel.mjs
132 changes: 108 additions & 24 deletions README.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions apps/astro/src/components/layout/NavLinks.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
---
import { activeNavItem, navItems } from '@/lib/site';
import { env } from '@packages/env';
const active = activeNavItem(Astro.url.pathname);
const forumUrl =
env.PUBLIC_FORUM_URL ??
(import.meta.env.DEV
? 'http://localhost:3000/'
: 'https://forum.manipalosf.org/');
---

{
Expand All @@ -16,3 +22,12 @@ const active = activeNavItem(Astro.url.pathname);
</li>
))
}
{
forumUrl && (
<li>
<a href={forumUrl} class='hover:text-foreground transition-colors'>
Forum
</a>
</li>
)
}
6 changes: 6 additions & 0 deletions apps/nextjs/auth-schema.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { betterAuth } from 'better-auth/minimal';
import { authOptions } from './src/lib/auth-options';

// Tooling only: schema generation needs the plugins, never live credentials.
// The CLI's --adapter and --dialect flags select Drizzle/PostgreSQL.
export const auth = betterAuth(authOptions);
5 changes: 5 additions & 0 deletions apps/nextjs/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'eslint/config';
import next from '@next/eslint-plugin-next';
import react from '@tooling/eslint/react';

export default defineConfig([...react, next.configs['core-web-vitals']]);
13 changes: 13 additions & 0 deletions apps/nextjs/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { NextConfig } from 'next';
import '@packages/env';

const config: NextConfig = {
reactStrictMode: true,
redirects() {
return [
{ source: '/forum/:path*', destination: '/:path*', permanent: true },
];
},
};

export default config;
50 changes: 50 additions & 0 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@apps/nextjs",
"private": true,
"type": "module",
"scripts": {
"dev": "with-env development next dev --port 3000",
"build": "with-env production next build",
"build:vercel": "node scripts/vercel-build.mjs",
"start": "with-env production next start --port 3000",
"lint": "eslint .",
"typecheck": "with-env production next typegen && tsc --noEmit",
"test": "tsx --test tests/*.test.ts",
"auth:generate": "pnpm dlx auth@1.7.7 generate --config ./auth-schema.config.ts --adapter drizzle --dialect postgresql --output ../../packages/db/src/schema/auth.ts --yes"
},
"dependencies": {
"@base-ui/react": "1.8.0",
"@fontsource-variable/cascadia-code": "5.3.0",
"@packages/auth": "workspace:*",
"@packages/db": "workspace:*",
"@packages/email": "workspace:*",
"@packages/env": "workspace:*",
"@packages/ui": "workspace:*",
"better-auth": "1.7.7",
"class-variance-authority": "0.7.1",
"drizzle-orm": "catalog:",
"lucide-react": "1.52.0",
"nanoid": "6.0.2",
"next": "16.4.0",
"react": "catalog:",
"react-dom": "catalog:",
"resend": "^6.32.1",
"server-only": "0.0.1",
"zod": "catalog:"
},
"devDependencies": {
"@better-auth/drizzle-adapter": "1.7.7",
"@electric-sql/pglite": "0.5.10",
"@next/eslint-plugin-next": "16.4.0",
"@tooling/eslint": "workspace:*",
"@tooling/tailwind": "workspace:*",
"@tooling/typescript": "workspace:*",
"@types/node": "catalog:",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"eslint": "catalog:",
"postcss": "catalog:",
"tsx": "4.23.15",
"typescript": "catalog:"
}
}
1 change: 1 addition & 0 deletions apps/nextjs/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@tooling/tailwind/postcss';
33 changes: 33 additions & 0 deletions apps/nextjs/scripts/vercel-build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';

let migration;
switch (process.env.VERCEL_ENV) {
case 'production':
migration = 'db:migrate:prod';
break;
case 'preview':
case 'development':
migration = 'db:migrate:dev';
break;
default:
console.error('VERCEL_ENV must be production, preview, or development.');
process.exit(1);
}

const root = fileURLToPath(new URL('../../../', import.meta.url));
for (const args of [
['--filter', '@packages/db', 'db:check'],
['--filter', '@packages/db', migration],
['--filter', '@apps/nextjs', 'build'],
]) {
const result = spawnSync('pnpm', args, { cwd: root, stdio: 'inherit' });
if (result.error) {
console.error(
`Unable to run pnpm ${args.join(' ')}: ${result.error.message}`,
);
}
if (result.status !== 0) {
process.exit(result.status ?? 1);
}
}
72 changes: 72 additions & 0 deletions apps/nextjs/src/app/(forum)/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use server';

import { revalidatePath } from 'next/cache';
import { z } from 'zod';
import { getForumContext } from '@/lib/forum';
import { ForumError } from '@/lib/forum-store';
import type { ForumActionResult } from '@/types/forum';

export async function forumAction(form: FormData): Promise<ForumActionResult> {
try {
const { store, viewer } = await getForumContext();
if (!store) return { error: 'The forum database is not configured yet.' };
if (!viewer)
return { error: 'Your session has ended. Log in again to participate.' };
const input = Object.fromEntries(form.entries());
let location: string | undefined;
let success = 'Saved.';
switch (input.action) {
case 'post': {
const id = await store.createPost(viewer, input);
location = `/item/${id}`;
break;
}
case 'comment': {
const id = await store.createComment(viewer, {
...input,
parentId: input.parentId || undefined,
});
location = `/item/${input.postId}#comment-${id}`;
success = 'Comment posted.';
break;
}
case 'vote':
await store.vote(viewer, { ...input, voted: input.voted === 'true' });
break;
case 'edit':
await store.edit(viewer, input);
break;
case 'delete':
await store.remove(viewer, input);
success = 'Deleted.';
break;
case 'report':
await store.report(viewer, input);
success = 'Report received. Thank you.';
break;
case 'moderate':
await store.moderate(viewer, {
...input,
reportId: input.reportId || undefined,
});
break;
default:
return { error: 'Unknown forum action.' };
}
revalidatePath('/(forum)', 'layout');
return { success, location };
} catch (error) {
if (error instanceof z.ZodError)
return { error: error.issues[0]?.message ?? 'Check your input.' };
if (error instanceof ForumError) return { error: error.message };
// Keep database errors, statements, and account information out of responses.
console.error(
'Forum action failed',
error instanceof Error ? error.name : 'Unknown error',
);
return {
error:
'Could not save your changes. Your draft is still here. Please try again.',
};
}
}
32 changes: 32 additions & 0 deletions apps/nextjs/src/app/(forum)/comments/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { getForumContext } from '@/lib/forum';
import { forumPage } from '@/lib/forum-store';
import ForumComments from '@/components/forum/ForumComments';
import {
ForumPagination,
ForumUnavailable,
} from '@/components/forum/ForumDisplay';

export default async function CommentsPage({
searchParams,
}: {
searchParams: Promise<{ page?: string }>;
}) {
const { store, viewer, moderator } = await getForumContext();
if (!store) return <ForumUnavailable />;
const result = await store.comments({
viewer,
page: forumPage((await searchParams).page),
});
return (
<>
<h1 className='mb-5 text-sm font-semibold'>Recent comments</h1>
<ForumComments
comments={result.comments}
viewer={!!viewer}
moderator={moderator}
threaded={false}
/>
<ForumPagination {...result} path='/comments' />
</>
);
}
12 changes: 12 additions & 0 deletions apps/nextjs/src/app/(forum)/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client';

export default function ForumError({ reset }: { reset: () => void }) {
return (
<div className='py-8 text-sm'>
<p role='alert'>We could not load the forum. Please try again.</p>
<button className='text-primary mt-3 underline' onClick={reset}>
Try again
</button>
</div>
);
}
79 changes: 79 additions & 0 deletions apps/nextjs/src/app/(forum)/item/[publicId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { notFound } from 'next/navigation';
import { getForumContext } from '@/lib/forum';
import {
PostRow,
ForumUnavailable,
SafeText,
} from '@/components/forum/ForumDisplay';
import { ContentControls } from '@/components/forum/ForumControls';
import ForumComments from '@/components/forum/ForumComments';
import ForumForm from '@/components/forum/ForumForm';

export default async function ItemPage({
params,
}: {
params: Promise<{ publicId: string }>;
}) {
const { publicId } = await params;
const { store, viewer, moderator } = await getForumContext();
if (!store) return <ForumUnavailable />;
const post = await store.post(publicId, viewer);
if (!post) notFound();
const { comments } = await store.comments({ postId: publicId, viewer });
return (
<div>
<h1 className='sr-only'>{post.title}</h1>
<PostRow post={post} viewer={!!viewer} />
{post.body && (
<div className='mt-5'>
<SafeText text={post.body} />
</div>
)}
{viewer && !post.deleted && (
<div className='mt-3'>
<ContentControls
id={post.id}
target='post'
owned={post.owned && !post.hidden}
moderator={moderator}
post={post}
/>
</div>
)}
<div className='my-7 max-w-2xl'>
{post.hidden ? (
<p className='text-muted-foreground text-sm'>
This discussion has been hidden by a moderator.
</p>
) : post.deleted ? (
<p className='text-muted-foreground text-sm'>
The author deleted this submission. Existing replies remain below.
</p>
) : post.locked ? (
<p className='text-muted-foreground text-sm'>
This discussion is locked to new replies.
</p>
) : viewer ? (
<ForumForm
action='comment'
fields={{ postId: post.id }}
label='Add comment'
>
<label>
Add a comment
<textarea name='body' required maxLength={10000} rows={4} />
</label>
</ForumForm>
) : (
<p className='text-sm'>Sign in to join the discussion.</p>
)}
</div>
<h2 className='mb-5 border-t pt-5 text-sm font-semibold'>Discussion</h2>
<ForumComments
comments={comments}
viewer={!!viewer}
moderator={moderator}
/>
</div>
);
}
Loading
Loading