Add community root-path middleware and fix login next= targets.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
eric 2026-09-28 19:07:54 -05:00
parent 0fc608ea26
commit 28998243c3
27 changed files with 166 additions and 37 deletions

View File

@ -95,7 +95,7 @@ export default function ProfilePage() {
useEffect(() => {
if (!token) {
router.push("/community/login?next=/profile");
router.push("/community/login?next=/community/profile");
return;
}
setLoading(true);

View File

@ -47,7 +47,7 @@ export default function ChatClient() {
<h2>{t.chat.loginTitle}</h2>
<p>{t.chat.loginDesc}</p>
<div className="dating-empty-actions">
<Link href="/community/login?next=/chat" className="btn btn-primary">{t.nav.login}</Link>
<Link href="/community/login?next=/community/chat" className="btn btn-primary">{t.nav.login}</Link>
<Link href="/community/meetups" className="btn btn-ghost">{t.dating.meetAtEvents}</Link>
<Link href="/community/dating" className="btn btn-ghost">{t.chat.goDating}</Link>
</div>

View File

@ -98,7 +98,7 @@ export default function ChatThreadClient({ convId }: { convId: string }) {
<h2>{t.chat.loginTitle}</h2>
<p>{t.chat.loginDesc}</p>
<div className="dating-empty-actions">
<Link href={`/login?next=/chat/${convId}`} className="btn btn-primary">
<Link href={`/community/login?next=/community/chat/${convId}`} className="btn btn-primary">
{t.nav.login}
</Link>
<Link href="/community/meetups" className="btn btn-ghost">

View File

@ -54,7 +54,7 @@ export default function ContentSubmitClient() {
const submit = async () => {
if (!token) {
router.push("/community/login?next=/submit");
router.push("/community/login?next=/community/submit");
return;
}
if (!title.trim() || title.trim().length < 4) {
@ -149,7 +149,7 @@ export default function ContentSubmitClient() {
</button>
{!token && (
<p className="section-desc">
<Link href="/community/login?next=/submit">{t.nav.login}</Link> · {t.gigs.loginFirst}
<Link href="/community/login?next=/community/submit">{t.nav.login}</Link> · {t.gigs.loginFirst}
</p>
)}
</div>

View File

@ -95,7 +95,7 @@ export default function DatingClient() {
const quickJoin = async () => {
if (!token) {
router.push("/community/login?next=/dating");
router.push("/community/login?next=/community/dating");
return;
}
setLoading(true);
@ -206,7 +206,7 @@ export default function DatingClient() {
<h2>{t.dating.loginTitle}</h2>
<p>{t.dating.loginDesc}</p>
<div className="dating-empty-actions">
<Link href="/community/login?next=/dating" className="btn btn-primary">{t.nav.login}</Link>
<Link href="/community/login?next=/community/dating" className="btn btn-primary">{t.nav.login}</Link>
<Link href="/community/meetups" className="btn btn-ghost">{t.dating.meetAtEvents}</Link>
<Link href="/community" className="btn btn-ghost">{t.nav.community}</Link>
</div>

View File

@ -46,7 +46,7 @@ export default function DatingLikesClient() {
<div className="container">
<div className="dating-gate reveal">
<h2>{t.dating.loginTitle}</h2>
<Link href="/community/login?next=/dating/likes" className="btn btn-primary">
<Link href="/community/login?next=/community/dating/likes" className="btn btn-primary">
{t.nav.login}
</Link>
</div>

View File

@ -128,7 +128,7 @@ export default function DigitalLessonClient({
<p>{t.digital.lockedDesc}</p>
<div className="dating-empty-actions">
{!token && (
<Link href={`/login?next=/digital/course/${moduleIndex}/${lessonIndex}`} className="btn">
<Link href={`/community/login?next=/community/digital/course/${moduleIndex}/${lessonIndex}`} className="btn">
{t.nav.login}
</Link>
)}

View File

@ -214,7 +214,7 @@ export default function DiscussionDetailClient({
<div className="community-reply-hint reveal">
<p>{t.community.replyHint}</p>
<div className="dating-empty-actions">
<Link href={`/login?next=/community/${discussionId}`} className="btn btn-primary">
<Link href={`/community/login?next=/community/${discussionId}`} className="btn btn-primary">
{t.nav.login}
</Link>
<Link href={meetupsHref} className="btn btn-ghost">

View File

@ -17,7 +17,7 @@ export default function FavoriteButton({ slug }: { slug: string }) {
if (!user) {
return (
<Link
href={`/login?next=${encodeURIComponent(next)}`}
href={`/community/login?next=${encodeURIComponent(next)}`}
className="btn btn-ghost"
style={{ fontSize: "0.85rem" }}
>

View File

@ -68,7 +68,7 @@ export default function Footer() {
</div>
<div className="footer-links">
<h4>{t.footer.account}</h4>
<Link href={`/login?next=${encodeURIComponent(loginNext)}`}>{t.footer.login}</Link>
<Link href={`/community/login?next=${encodeURIComponent(loginNext)}`}>{t.footer.login}</Link>
<Link href="/community/help">{t.footer.help}</Link>
<Link href="/community/about">{t.footer.about}</Link>
<Link href="/community/privacy">{t.footer.privacy}</Link>

View File

@ -59,7 +59,7 @@ export default function GigPostClient() {
<div className="dating-gate reveal">
<h2>{t.gigs.postTitle}</h2>
<p>{t.gigs.loginFirst}</p>
<Link href="/community/login?next=/gigs/post" className="btn btn-primary">{t.nav.login}</Link>
<Link href="/community/login?next=/community/gigs/post" className="btn btn-primary">{t.nav.login}</Link>
</div>
</div>
</div>
@ -68,7 +68,7 @@ export default function GigPostClient() {
const submit = async () => {
if (!token) {
router.push("/community/login?next=/gigs/post");
router.push("/community/login?next=/community/gigs/post");
return;
}
if (!title.trim() || !description.trim()) {

View File

@ -50,7 +50,7 @@ export default function GigsClient({ gigs }: { gigs: GigItem[] }) {
const apply = async (id: string) => {
if (!token) {
router.push("/community/login?next=/gigs");
router.push("/community/login?next=/community/gigs");
return;
}
const message = msg[id]?.trim();
@ -133,7 +133,7 @@ export default function GigsClient({ gigs }: { gigs: GigItem[] }) {
<div className="digital-jobs-grid reveal">
{!token && (
<p className="section-desc reveal">
<Link href="/community/login?next=/gigs">{t.nav.login}</Link> · {t.gigs.loginFirst}
<Link href="/community/login?next=/community/gigs">{t.nav.login}</Link> · {t.gigs.loginFirst}
</p>
)}
{gigs.map((g) => {
@ -155,7 +155,7 @@ export default function GigsClient({ gigs }: { gigs: GigItem[] }) {
{applied[g.id] ? (
<p className="gigs-applied">{t.gigs.applied}</p>
) : !token ? (
<Link href="/community/login?next=/gigs" className="btn btn-primary btn-sm">
<Link href="/community/login?next=/community/gigs" className="btn btn-primary btn-sm">
{t.gigs.apply}
</Link>
) : (

View File

@ -62,7 +62,7 @@ export default function JoinClient() {
const submit = async () => {
if (!token) {
router.push("/community/login?next=/join");
router.push("/community/login?next=/community/join");
return;
}
setLoading(true);
@ -85,7 +85,7 @@ export default function JoinClient() {
const pay = async () => {
if (!token) {
router.push("/community/login?next=/join");
router.push("/community/login?next=/community/join");
return;
}
if (vip) {
@ -151,7 +151,7 @@ export default function JoinClient() {
{vip ? t.join.goDating : t.join.payBtn}
</button>
{!vip && <p className="section-desc join-pay-note">{t.join.payMethods}</p>}
{!user && <Link href="/community/login?next=/join" className="join-login-hint">{t.nav.login}</Link>}
{!user && <Link href="/community/login?next=/community/join" className="join-login-hint">{t.nav.login}</Link>}
</div>
</div>

View File

@ -63,7 +63,7 @@ export default function JoinPaidClient() {
{status === "need-login" && (
<>
<h2>{t.join.paidFail}</h2>
<Link href="/community/login?next=/join/paid" className="btn btn-primary">{t.nav.login}</Link>
<Link href="/community/login?next=/community/join/paid" className="btn btn-primary">{t.nav.login}</Link>
</>
)}
{status === "ok" && (

View File

@ -146,7 +146,7 @@ export default function MeetupLiveClient({
{t.live.back}
</Link>
) : (
<Link href={`/login?next=/meetups/${meetupId}/live`} className="btn btn-primary">
<Link href={`/community/login?next=/community/meetups/${meetupId}/live`} className="btn btn-primary">
{t.nav.login}
</Link>
)}

View File

@ -172,7 +172,7 @@ export default function MeetupsClient({ meetups }: Props) {
<p>{t.meetups.subtitle}</p>
{!token && (
<p className="meetups-login-hint">
<Link href="/community/login?next=/meetups">{t.nav.login}</Link> · {t.meetups.loginHint}
<Link href="/community/login?next=/community/meetups">{t.nav.login}</Link> · {t.meetups.loginHint}
</p>
)}
</div>

View File

@ -96,7 +96,7 @@ export default function MeetupsHostClient() {
<div className="dating-gate reveal">
<h2>{t.meetups.hostTitle}</h2>
<p>{t.meetups.loginDesc}</p>
<Link href="/community/login?next=/meetups/host" className="btn btn-primary">{t.nav.login}</Link>
<Link href="/community/login?next=/community/meetups/host" className="btn btn-primary">{t.nav.login}</Link>
</div>
</div>
</div>
@ -105,7 +105,7 @@ export default function MeetupsHostClient() {
const submit = async () => {
if (!token) {
router.push("/community/login?next=/meetups/host");
router.push("/community/login?next=/community/meetups/host");
return;
}
if (!form.title.trim() || !form.date) {

View File

@ -51,7 +51,7 @@ export default function MemberProfileClient({ profile }: { profile: MemberProfil
const likeBack = async () => {
if (!token) {
router.push(`/community/login?next=/members/${memberHref}`);
router.push(`/community/login?next=/community/members/${memberHref}`);
return;
}
if (!profileId || liking) return;
@ -127,7 +127,7 @@ export default function MemberProfileClient({ profile }: { profile: MemberProfil
{liking ? "…" : t.dating.likeBack}
</button>
) : (
<Link href={`/login?next=/members/${memberHref}`} className="btn btn-primary btn-sm">
<Link href={`/community/login?next=/community/members/${memberHref}`} className="btn btn-primary btn-sm">
{t.nav.login}
</Link>
)}

View File

@ -344,7 +344,7 @@ export default function MovePlanClient({ destinations, visas = [] }: Props) {
</button>
</>
) : (
<Link href="/community/login?next=/plan" className="plan-sync-pill idle">{t.plan.loginSync}</Link>
<Link href="/community/login?next=/community/plan" className="plan-sync-pill idle">{t.plan.loginSync}</Link>
)}
</div>
<div className="plan-meta-row">

View File

@ -218,7 +218,7 @@ export default function Navbar() {
<div className="nav-mobile-extras">
{!user && (
<Link
href={`/login?next=${encodeURIComponent(loginNext)}`}
href={`/community/login?next=${encodeURIComponent(loginNext)}`}
className="nav-login-btn"
onClick={closeAll}
>
@ -247,7 +247,7 @@ export default function Navbar() {
</Link>
) : (
<Link
href={`/login?next=${encodeURIComponent("/chat")}`}
href={`/community/login?next=${encodeURIComponent("/chat")}`}
className="nav-notify nav-notify-guest"
aria-label={t.nav.chat}
title={t.nav.login}
@ -261,7 +261,7 @@ export default function Navbar() {
</Link>
) : (
<Link
href={`/login?next=${encodeURIComponent(loginNext)}`}
href={`/community/login?next=${encodeURIComponent(loginNext)}`}
className="nav-notify nav-notify-guest"
aria-label={t.nav.notifications}
title={t.nav.login}
@ -281,7 +281,7 @@ export default function Navbar() {
</Link>
) : (
<Link
href={`/login?next=${encodeURIComponent(loginNext)}`}
href={`/community/login?next=${encodeURIComponent(loginNext)}`}
className="nav-login-btn nav-login-desktop"
>
{t.nav.login}

View File

@ -65,7 +65,7 @@ export default function NotificationSettingsClient() {
<div className="dating-gate reveal">
<h2>{t.notifSettings.title}</h2>
<p>{t.notifSettings.loginDesc}</p>
<Link href="/community/login?next=/settings/notifications" className="btn btn-primary">
<Link href="/community/login?next=/community/settings/notifications" className="btn btn-primary">
{t.nav.login}
</Link>
</div>

View File

@ -50,7 +50,7 @@ export default function NotificationsClient() {
<h2>{t.notifications.title}</h2>
<p>{t.notifications.loginDesc}</p>
<div className="dating-empty-actions">
<Link href="/community/login?next=/notifications" className="btn btn-primary">
<Link href="/community/login?next=/community/notifications" className="btn btn-primary">
{t.nav.login}
</Link>
<Link href="/community/meetups" className="btn btn-ghost">

View File

@ -80,7 +80,7 @@ export function AdminConsole() {
async function login() {
setLoading(true);
try {
const res = await fetch('/api/admin/login', { method: 'POST', headers: { Authorization: auth } });
const res = await fetch('/api/admin/community/login', { method: 'POST', headers: { Authorization: auth } });
const body = (await res.json()) as { ok?: boolean; error?: string };
if (!res.ok || !body.ok) throw new Error(body.error || t('admin.loginFailed'));
setAuthorized(true);

View File

@ -133,7 +133,7 @@ export const api = {
getChartRadar: () => fetchWithFallback<ChartData>("/charts/radar", { labels: [], datasets: [] }),
// Auth
login: (email: string, password: string) =>
fetchAPI<AuthResponse>("/auth/login", { method: "POST", body: JSON.stringify({ email, password }) }),
fetchAPI<AuthResponse>("/auth/community/login", { method: "POST", body: JSON.stringify({ email, password }) }),
register: (email: string, password: string, name: string) =>
fetchAPI<AuthResponse>("/auth/register", { method: "POST", body: JSON.stringify({ email, password, name }) }),
demoLogin: () => fetchAPI<AuthResponse>("/auth/demo"),

View File

@ -64,7 +64,7 @@ export interface AuthNextMeta {
/** Post-login redirect when opening login from site chrome */
export function loginNextFrom(pathname: string | null): string {
if (!pathname || pathname === "/" || pathname === "/login") return "/profile";
if (!pathname || pathname === "/" || pathname === "/community/login") return "/profile";
return pathname;
}

85
middleware.ts Normal file
View File

@ -0,0 +1,85 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
/**
* Compat redirects for vertical apps mounted under path prefixes.
* Old standalone URLs → portal mounts.
*/
const COMMUNITY_ROOTS = new Set([
"about",
"ai",
"blog",
"careers",
"changelog",
"chat",
"compare",
"contact",
"cookies",
"dating",
"destinations",
"digital",
"feedback",
"gigs",
"guidelines",
"help",
"join",
"login",
"map",
"meetups",
"members",
"next-stop",
"notifications",
"plan",
"press",
"pricing",
"privacy",
"profile",
"report",
"safety",
"services",
"settings",
"submit",
"support",
"terms",
"tools",
"videos",
]);
export function middleware(request: NextRequest) {
const { pathname, search } = request.nextUrl;
// /read and /read/* already handled by app/read routes.
// Extra: bare community routes that used to live at site root.
const seg = pathname.split("/").filter(Boolean)[0];
if (
seg &&
COMMUNITY_ROOTS.has(seg) &&
!pathname.startsWith("/community/") &&
pathname !== "/community"
) {
const url = request.nextUrl.clone();
url.pathname = `/community${pathname}`;
return NextResponse.redirect(url, 308);
}
// Fix login?next=/foo → next=/community/foo when missing prefix
if (pathname === "/community/login" || pathname === "/login") {
const next = request.nextUrl.searchParams.get("next");
if (next && next.startsWith("/") && !next.startsWith("/community") && !next.startsWith("/book") && !next.startsWith("/nav") && !next.startsWith("/http")) {
const url = request.nextUrl.clone();
if (pathname === "/login") {
url.pathname = "/community/login";
}
url.searchParams.set("next", `/community${next === "/" ? "" : next}`);
return NextResponse.redirect(url, 308);
}
}
return NextResponse.next();
}
export const config = {
matcher: [
"/((?!_next/static|_next/image|favicon.ico|icons/|api/|.*\\..*).*)",
],
};

View File

@ -0,0 +1,44 @@
#!/usr/bin/env python3
from __future__ import annotations
import pathlib
import re
ROOT = pathlib.Path(__file__).resolve().parents[1] / "apps/nomadweb/frontend/src"
def fix(text: str) -> str:
t = text
t = re.sub(r"(?<!/community)/login\?", "/community/login?", t)
t = re.sub(r'(?<!/community)/login"', '/community/login"', t)
t = re.sub(r"(?<!/community)/login'", "/community/login'", t)
def repl_next(m: re.Match[str]) -> str:
path = m.group(1)
if path.startswith(("/community", "/book", "/nav", "http")):
return m.group(0)
if not path.startswith("/"):
path = "/" + path
return f"next=/community{path}"
t = re.sub(r"next=(/[^\s\"'?]+)", repl_next, t)
t = t.replace("/community/community/", "/community/")
return t
def main() -> None:
n = 0
for p in ROOT.rglob("*"):
if p.suffix not in {".ts", ".tsx"}:
continue
raw = p.read_text(encoding="utf-8")
out = fix(raw)
if out != raw:
p.write_text(out, encoding="utf-8")
n += 1
print("fixed", p.relative_to(ROOT))
print("files", n)
if __name__ == "__main__":
main()