Add community root-path middleware and fix login next= targets.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
0fc608ea26
commit
28998243c3
@ -95,7 +95,7 @@ export default function ProfilePage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/profile");
|
router.push("/community/login?next=/community/profile");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export default function ChatClient() {
|
|||||||
<h2>{t.chat.loginTitle}</h2>
|
<h2>{t.chat.loginTitle}</h2>
|
||||||
<p>{t.chat.loginDesc}</p>
|
<p>{t.chat.loginDesc}</p>
|
||||||
<div className="dating-empty-actions">
|
<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/meetups" className="btn btn-ghost">{t.dating.meetAtEvents}</Link>
|
||||||
<Link href="/community/dating" className="btn btn-ghost">{t.chat.goDating}</Link>
|
<Link href="/community/dating" className="btn btn-ghost">{t.chat.goDating}</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -98,7 +98,7 @@ export default function ChatThreadClient({ convId }: { convId: string }) {
|
|||||||
<h2>{t.chat.loginTitle}</h2>
|
<h2>{t.chat.loginTitle}</h2>
|
||||||
<p>{t.chat.loginDesc}</p>
|
<p>{t.chat.loginDesc}</p>
|
||||||
<div className="dating-empty-actions">
|
<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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/community/meetups" className="btn btn-ghost">
|
<Link href="/community/meetups" className="btn btn-ghost">
|
||||||
|
|||||||
@ -54,7 +54,7 @@ export default function ContentSubmitClient() {
|
|||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/submit");
|
router.push("/community/login?next=/community/submit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!title.trim() || title.trim().length < 4) {
|
if (!title.trim() || title.trim().length < 4) {
|
||||||
@ -149,7 +149,7 @@ export default function ContentSubmitClient() {
|
|||||||
</button>
|
</button>
|
||||||
{!token && (
|
{!token && (
|
||||||
<p className="section-desc">
|
<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>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -95,7 +95,7 @@ export default function DatingClient() {
|
|||||||
|
|
||||||
const quickJoin = async () => {
|
const quickJoin = async () => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/dating");
|
router.push("/community/login?next=/community/dating");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -206,7 +206,7 @@ export default function DatingClient() {
|
|||||||
<h2>{t.dating.loginTitle}</h2>
|
<h2>{t.dating.loginTitle}</h2>
|
||||||
<p>{t.dating.loginDesc}</p>
|
<p>{t.dating.loginDesc}</p>
|
||||||
<div className="dating-empty-actions">
|
<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/meetups" className="btn btn-ghost">{t.dating.meetAtEvents}</Link>
|
||||||
<Link href="/community" className="btn btn-ghost">{t.nav.community}</Link>
|
<Link href="/community" className="btn btn-ghost">{t.nav.community}</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -46,7 +46,7 @@ export default function DatingLikesClient() {
|
|||||||
<div className="container">
|
<div className="container">
|
||||||
<div className="dating-gate reveal">
|
<div className="dating-gate reveal">
|
||||||
<h2>{t.dating.loginTitle}</h2>
|
<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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -128,7 +128,7 @@ export default function DigitalLessonClient({
|
|||||||
<p>{t.digital.lockedDesc}</p>
|
<p>{t.digital.lockedDesc}</p>
|
||||||
<div className="dating-empty-actions">
|
<div className="dating-empty-actions">
|
||||||
{!token && (
|
{!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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -214,7 +214,7 @@ export default function DiscussionDetailClient({
|
|||||||
<div className="community-reply-hint reveal">
|
<div className="community-reply-hint reveal">
|
||||||
<p>{t.community.replyHint}</p>
|
<p>{t.community.replyHint}</p>
|
||||||
<div className="dating-empty-actions">
|
<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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
<Link href={meetupsHref} className="btn btn-ghost">
|
<Link href={meetupsHref} className="btn btn-ghost">
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export default function FavoriteButton({ slug }: { slug: string }) {
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
href={`/login?next=${encodeURIComponent(next)}`}
|
href={`/community/login?next=${encodeURIComponent(next)}`}
|
||||||
className="btn btn-ghost"
|
className="btn btn-ghost"
|
||||||
style={{ fontSize: "0.85rem" }}
|
style={{ fontSize: "0.85rem" }}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -68,7 +68,7 @@ export default function Footer() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="footer-links">
|
<div className="footer-links">
|
||||||
<h4>{t.footer.account}</h4>
|
<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/help">{t.footer.help}</Link>
|
||||||
<Link href="/community/about">{t.footer.about}</Link>
|
<Link href="/community/about">{t.footer.about}</Link>
|
||||||
<Link href="/community/privacy">{t.footer.privacy}</Link>
|
<Link href="/community/privacy">{t.footer.privacy}</Link>
|
||||||
|
|||||||
@ -59,7 +59,7 @@ export default function GigPostClient() {
|
|||||||
<div className="dating-gate reveal">
|
<div className="dating-gate reveal">
|
||||||
<h2>{t.gigs.postTitle}</h2>
|
<h2>{t.gigs.postTitle}</h2>
|
||||||
<p>{t.gigs.loginFirst}</p>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -68,7 +68,7 @@ export default function GigPostClient() {
|
|||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/gigs/post");
|
router.push("/community/login?next=/community/gigs/post");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!title.trim() || !description.trim()) {
|
if (!title.trim() || !description.trim()) {
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export default function GigsClient({ gigs }: { gigs: GigItem[] }) {
|
|||||||
|
|
||||||
const apply = async (id: string) => {
|
const apply = async (id: string) => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/gigs");
|
router.push("/community/login?next=/community/gigs");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const message = msg[id]?.trim();
|
const message = msg[id]?.trim();
|
||||||
@ -133,7 +133,7 @@ export default function GigsClient({ gigs }: { gigs: GigItem[] }) {
|
|||||||
<div className="digital-jobs-grid reveal">
|
<div className="digital-jobs-grid reveal">
|
||||||
{!token && (
|
{!token && (
|
||||||
<p className="section-desc reveal">
|
<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>
|
</p>
|
||||||
)}
|
)}
|
||||||
{gigs.map((g) => {
|
{gigs.map((g) => {
|
||||||
@ -155,7 +155,7 @@ export default function GigsClient({ gigs }: { gigs: GigItem[] }) {
|
|||||||
{applied[g.id] ? (
|
{applied[g.id] ? (
|
||||||
<p className="gigs-applied">{t.gigs.applied}</p>
|
<p className="gigs-applied">{t.gigs.applied}</p>
|
||||||
) : !token ? (
|
) : !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}
|
{t.gigs.apply}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@ -62,7 +62,7 @@ export default function JoinClient() {
|
|||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/join");
|
router.push("/community/login?next=/community/join");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -85,7 +85,7 @@ export default function JoinClient() {
|
|||||||
|
|
||||||
const pay = async () => {
|
const pay = async () => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/join");
|
router.push("/community/login?next=/community/join");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (vip) {
|
if (vip) {
|
||||||
@ -151,7 +151,7 @@ export default function JoinClient() {
|
|||||||
{vip ? t.join.goDating : t.join.payBtn}
|
{vip ? t.join.goDating : t.join.payBtn}
|
||||||
</button>
|
</button>
|
||||||
{!vip && <p className="section-desc join-pay-note">{t.join.payMethods}</p>}
|
{!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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@ export default function JoinPaidClient() {
|
|||||||
{status === "need-login" && (
|
{status === "need-login" && (
|
||||||
<>
|
<>
|
||||||
<h2>{t.join.paidFail}</h2>
|
<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" && (
|
{status === "ok" && (
|
||||||
|
|||||||
@ -146,7 +146,7 @@ export default function MeetupLiveClient({
|
|||||||
{t.live.back}
|
{t.live.back}
|
||||||
</Link>
|
</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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -172,7 +172,7 @@ export default function MeetupsClient({ meetups }: Props) {
|
|||||||
<p>{t.meetups.subtitle}</p>
|
<p>{t.meetups.subtitle}</p>
|
||||||
{!token && (
|
{!token && (
|
||||||
<p className="meetups-login-hint">
|
<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>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -96,7 +96,7 @@ export default function MeetupsHostClient() {
|
|||||||
<div className="dating-gate reveal">
|
<div className="dating-gate reveal">
|
||||||
<h2>{t.meetups.hostTitle}</h2>
|
<h2>{t.meetups.hostTitle}</h2>
|
||||||
<p>{t.meetups.loginDesc}</p>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -105,7 +105,7 @@ export default function MeetupsHostClient() {
|
|||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push("/community/login?next=/meetups/host");
|
router.push("/community/login?next=/community/meetups/host");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!form.title.trim() || !form.date) {
|
if (!form.title.trim() || !form.date) {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ export default function MemberProfileClient({ profile }: { profile: MemberProfil
|
|||||||
|
|
||||||
const likeBack = async () => {
|
const likeBack = async () => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
router.push(`/community/login?next=/members/${memberHref}`);
|
router.push(`/community/login?next=/community/members/${memberHref}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!profileId || liking) return;
|
if (!profileId || liking) return;
|
||||||
@ -127,7 +127,7 @@ export default function MemberProfileClient({ profile }: { profile: MemberProfil
|
|||||||
{liking ? "…" : t.dating.likeBack}
|
{liking ? "…" : t.dating.likeBack}
|
||||||
</button>
|
</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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -344,7 +344,7 @@ export default function MovePlanClient({ destinations, visas = [] }: Props) {
|
|||||||
</button>
|
</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>
|
||||||
<div className="plan-meta-row">
|
<div className="plan-meta-row">
|
||||||
|
|||||||
@ -218,7 +218,7 @@ export default function Navbar() {
|
|||||||
<div className="nav-mobile-extras">
|
<div className="nav-mobile-extras">
|
||||||
{!user && (
|
{!user && (
|
||||||
<Link
|
<Link
|
||||||
href={`/login?next=${encodeURIComponent(loginNext)}`}
|
href={`/community/login?next=${encodeURIComponent(loginNext)}`}
|
||||||
className="nav-login-btn"
|
className="nav-login-btn"
|
||||||
onClick={closeAll}
|
onClick={closeAll}
|
||||||
>
|
>
|
||||||
@ -247,7 +247,7 @@ export default function Navbar() {
|
|||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<Link
|
<Link
|
||||||
href={`/login?next=${encodeURIComponent("/chat")}`}
|
href={`/community/login?next=${encodeURIComponent("/chat")}`}
|
||||||
className="nav-notify nav-notify-guest"
|
className="nav-notify nav-notify-guest"
|
||||||
aria-label={t.nav.chat}
|
aria-label={t.nav.chat}
|
||||||
title={t.nav.login}
|
title={t.nav.login}
|
||||||
@ -261,7 +261,7 @@ export default function Navbar() {
|
|||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<Link
|
<Link
|
||||||
href={`/login?next=${encodeURIComponent(loginNext)}`}
|
href={`/community/login?next=${encodeURIComponent(loginNext)}`}
|
||||||
className="nav-notify nav-notify-guest"
|
className="nav-notify nav-notify-guest"
|
||||||
aria-label={t.nav.notifications}
|
aria-label={t.nav.notifications}
|
||||||
title={t.nav.login}
|
title={t.nav.login}
|
||||||
@ -281,7 +281,7 @@ export default function Navbar() {
|
|||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<Link
|
<Link
|
||||||
href={`/login?next=${encodeURIComponent(loginNext)}`}
|
href={`/community/login?next=${encodeURIComponent(loginNext)}`}
|
||||||
className="nav-login-btn nav-login-desktop"
|
className="nav-login-btn nav-login-desktop"
|
||||||
>
|
>
|
||||||
{t.nav.login}
|
{t.nav.login}
|
||||||
|
|||||||
@ -65,7 +65,7 @@ export default function NotificationSettingsClient() {
|
|||||||
<div className="dating-gate reveal">
|
<div className="dating-gate reveal">
|
||||||
<h2>{t.notifSettings.title}</h2>
|
<h2>{t.notifSettings.title}</h2>
|
||||||
<p>{t.notifSettings.loginDesc}</p>
|
<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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export default function NotificationsClient() {
|
|||||||
<h2>{t.notifications.title}</h2>
|
<h2>{t.notifications.title}</h2>
|
||||||
<p>{t.notifications.loginDesc}</p>
|
<p>{t.notifications.loginDesc}</p>
|
||||||
<div className="dating-empty-actions">
|
<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}
|
{t.nav.login}
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/community/meetups" className="btn btn-ghost">
|
<Link href="/community/meetups" className="btn btn-ghost">
|
||||||
|
|||||||
@ -80,7 +80,7 @@ export function AdminConsole() {
|
|||||||
async function login() {
|
async function login() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
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 };
|
const body = (await res.json()) as { ok?: boolean; error?: string };
|
||||||
if (!res.ok || !body.ok) throw new Error(body.error || t('admin.loginFailed'));
|
if (!res.ok || !body.ok) throw new Error(body.error || t('admin.loginFailed'));
|
||||||
setAuthorized(true);
|
setAuthorized(true);
|
||||||
|
|||||||
@ -133,7 +133,7 @@ export const api = {
|
|||||||
getChartRadar: () => fetchWithFallback<ChartData>("/charts/radar", { labels: [], datasets: [] }),
|
getChartRadar: () => fetchWithFallback<ChartData>("/charts/radar", { labels: [], datasets: [] }),
|
||||||
// Auth
|
// Auth
|
||||||
login: (email: string, password: string) =>
|
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) =>
|
register: (email: string, password: string, name: string) =>
|
||||||
fetchAPI<AuthResponse>("/auth/register", { method: "POST", body: JSON.stringify({ email, password, name }) }),
|
fetchAPI<AuthResponse>("/auth/register", { method: "POST", body: JSON.stringify({ email, password, name }) }),
|
||||||
demoLogin: () => fetchAPI<AuthResponse>("/auth/demo"),
|
demoLogin: () => fetchAPI<AuthResponse>("/auth/demo"),
|
||||||
|
|||||||
@ -64,7 +64,7 @@ export interface AuthNextMeta {
|
|||||||
|
|
||||||
/** Post-login redirect when opening login from site chrome */
|
/** Post-login redirect when opening login from site chrome */
|
||||||
export function loginNextFrom(pathname: string | null): string {
|
export function loginNextFrom(pathname: string | null): string {
|
||||||
if (!pathname || pathname === "/" || pathname === "/login") return "/profile";
|
if (!pathname || pathname === "/" || pathname === "/community/login") return "/profile";
|
||||||
return pathname;
|
return pathname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
85
middleware.ts
Normal file
85
middleware.ts
Normal 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/|.*\\..*).*)",
|
||||||
|
],
|
||||||
|
};
|
||||||
44
scripts/fix-community-login-next.py
Normal file
44
scripts/fix-community-login-next.py
Normal 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()
|
||||||
Loading…
Reference in New Issue
Block a user