From b3031b79d163f9568efb03e501ec68c61649de02 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 5 Aug 2025 17:12:53 +0200 Subject: [PATCH] Restrict userbase access to logged-in users --- app/page.tsx | 111 +++++++++++++++++++++--------------------- app/profiles/page.tsx | 12 ++++- app/register/page.tsx | 4 +- 3 files changed, 67 insertions(+), 60 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 38aa39c..e0c5aaf 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -2,56 +2,48 @@ import ProfilePage from "@/app/profiles/page"; import Link from "next/link"; -import React from 'react'; // ← Add this line here +import {useEffect} from 'react'; +import {useSession} from "next-auth/react"; // ← Add this line here export const dynamic = "force-dynamic"; // This disables SSG and ISR export default function HomePage() { - const profilePage = () => { - return ( -
- -
- ) - } + const {data: session} = useSession(); + const userId = session?.user?.id + console.log("session:", userId) + const fontStyle = "transition px-5 py-3 text-3xl font-medium xs:text-sm" - -React.useEffect(() => { - const text = "Search."; - const typewriter = document.getElementById("typewriter"); - let i = 0; - let timeoutId: any; - let intervalId; - - // Clear any existing content - if (typewriter) { - typewriter.textContent = ""; - } - - function typeWriter() { - if (i < text.length && typewriter) { - typewriter.textContent = text.substring(0, i + 1); - i++; - timeoutId = setTimeout(typeWriter, 150); + useEffect(() => { + const text = "Search."; + const typewriter = document.getElementById("typewriter"); + let i = 0; + let timeoutId: any; + let intervalId; + + // Clear any existing content + if (typewriter) typewriter.textContent = "" + + function typeWriter() { + if (i < text.length && typewriter) { + typewriter.textContent = text.substring(0, i + 1); + i++; + timeoutId = setTimeout(typeWriter, 150); + } } - } - - // Start typing after delay - intervalId = setTimeout(() => { - typeWriter(); - }, 500); - - // Cleanup function - this runs when component unmounts - return () => { - clearTimeout(timeoutId); - clearTimeout(intervalId); - if (typewriter) { - typewriter.textContent = "Search."; // Just show the full text - } - }; -}, []); + + // Start typing after delay + intervalId = setTimeout(() => typeWriter(), 500); + + // Cleanup function - this runs when component unmounts + return () => { + clearTimeout(timeoutId); + clearTimeout(intervalId); + if (typewriter) typewriter.textContent = "Search." + }; + }, []); + return (
{/* Header */} @@ -70,8 +62,9 @@ React.useEffect(() => { {/* Hero Section */}
-
-

+
+

Don't Swipe. |

{/*

*/} @@ -79,16 +72,16 @@ React.useEffect(() => { {/*

*/} {/* Spacer */}
-
- +
+ Join Compass - - {/* Spacer */} -
+ {/* Spacer */} + {/*
*/}
{/* Why Compass Bar */} -
+
@@ -97,14 +90,14 @@ React.useEffect(() => { No algorithms. Every profile searchable.

- +

Built for Depth

Filter by any keyword and what matters most.

- +

Community Owned

@@ -115,10 +108,16 @@ React.useEffect(() => {

{/* Spacer */} -
-
- {profilePage()} -
+ {userId && + <> + {/*
*/} +
+
+ +
+
+ + }
); diff --git a/app/profiles/page.tsx b/app/profiles/page.tsx index 7263ea8..ec5b1dc 100644 --- a/app/profiles/page.tsx +++ b/app/profiles/page.tsx @@ -5,6 +5,7 @@ import React, {useCallback, useEffect, useState} from "react"; import {DropdownKey, ProfileData} from "@/lib/client/schema"; import {dropdownConfig, ProfileFilters} from "./ProfileFilters"; import Image from "next/image"; +import {useSession} from "next-auth/react"; // Disable static generation export const dynamic = "force-dynamic"; @@ -41,6 +42,12 @@ type ProfileFilters = { export default function ProfilePage() { + const {data: session} = useSession(); + const userId = session?.user?.id + console.log("session:", userId) + + // if (!userId) return
+ const [profiles, setProfiles] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); @@ -63,8 +70,7 @@ export default function ProfilePage() { if (key === 'searchQuery') { setText(value); newFilters[filterKey] = value as never; - } - else if (['interests', 'coreValues', 'causeAreas', 'connections'].includes(key)) { + } else if (['interests', 'coreValues', 'causeAreas', 'connections'].includes(key)) { const arrayKey = filterKey as 'interests' | 'coreValues' | 'causeAreas' | 'connections'; newFilters[arrayKey] = [...newFilters[arrayKey], value]; } else { @@ -182,6 +188,8 @@ export default function ProfilePage() { const onFilterChange = handleFilterChange + if (!userId) return
+ return (
diff --git a/app/register/page.tsx b/app/register/page.tsx index add4926..feb3379 100644 --- a/app/register/page.tsx +++ b/app/register/page.tsx @@ -5,7 +5,7 @@ import Link from "next/link"; import {signIn} from "next-auth/react"; import {FcGoogle} from "react-icons/fc"; import {useSearchParams} from "next/navigation"; -import Image from "next/image"; +import {favIcon} from "@/lib/client/media"; export default function RegisterPage() { @@ -149,7 +149,7 @@ function RegisterComponent() { {/* The project is still in development...*/} {/**/}
- Compass logo + {favIcon()}

Get Started