Skip to content

Commit b3031b7

Browse files
committed
Restrict userbase access to logged-in users
1 parent cc679dd commit b3031b7

File tree

3 files changed

+67
-60
lines changed

3 files changed

+67
-60
lines changed

app/page.tsx

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,48 @@
22

33
import ProfilePage from "@/app/profiles/page";
44
import Link from "next/link";
5-
import React from 'react'; // ← Add this line here
5+
import {useEffect} from 'react';
6+
import {useSession} from "next-auth/react"; // ← Add this line here
67

78
export const dynamic = "force-dynamic"; // This disables SSG and ISR
89

910

1011
export default function HomePage() {
11-
const profilePage = () => {
12-
return (
13-
<main className="min-h-screen flex flex-col">
14-
<ProfilePage/>
15-
</main>
16-
)
17-
}
12+
const {data: session} = useSession();
13+
const userId = session?.user?.id
14+
console.log("session:", userId)
15+
1816
const fontStyle = "transition px-5 py-3 text-3xl font-medium xs:text-sm"
1917

20-
21-
React.useEffect(() => {
22-
const text = "Search.";
23-
const typewriter = document.getElementById("typewriter");
24-
let i = 0;
25-
let timeoutId: any;
26-
let intervalId;
27-
28-
// Clear any existing content
29-
if (typewriter) {
30-
typewriter.textContent = "";
31-
}
32-
33-
function typeWriter() {
34-
if (i < text.length && typewriter) {
35-
typewriter.textContent = text.substring(0, i + 1);
36-
i++;
37-
timeoutId = setTimeout(typeWriter, 150);
38-
}
39-
}
40-
41-
// Start typing after delay
42-
intervalId = setTimeout(() => {
43-
typeWriter();
44-
}, 500);
45-
46-
// Cleanup function - this runs when component unmounts
47-
return () => {
48-
clearTimeout(timeoutId);
49-
clearTimeout(intervalId);
50-
if (typewriter) {
51-
typewriter.textContent = "Search."; // Just show the full text
18+
useEffect(() => {
19+
const text = "Search.";
20+
const typewriter = document.getElementById("typewriter");
21+
let i = 0;
22+
let timeoutId: any;
23+
let intervalId;
24+
25+
// Clear any existing content
26+
if (typewriter) typewriter.textContent = ""
27+
28+
function typeWriter() {
29+
if (i < text.length && typewriter) {
30+
typewriter.textContent = text.substring(0, i + 1);
31+
i++;
32+
timeoutId = setTimeout(typeWriter, 150);
33+
}
5234
}
53-
};
54-
}, []);
35+
36+
// Start typing after delay
37+
intervalId = setTimeout(() => typeWriter(), 500);
38+
39+
// Cleanup function - this runs when component unmounts
40+
return () => {
41+
clearTimeout(timeoutId);
42+
clearTimeout(intervalId);
43+
if (typewriter) typewriter.textContent = "Search."
44+
};
45+
}, []);
46+
5547
return (
5648
<main className="min-h-screen flex flex-col">
5749
{/* Header */}
@@ -70,25 +62,26 @@ React.useEffect(() => {
7062

7163
{/* Hero Section */}
7264
<section className="flex flex-col items-center justify-start flex-1 text-center px-4">
73-
<div className="h-20"></div>
74-
<h1 className="pt-48 pb-2 text-7xl md:text-8xl xs:text-6xl font-extrabold max-w-4xl leading-tight xl:whitespace-nowrap md:whitespace-nowrap ">
65+
<div className="h-10"></div>
66+
<h1
67+
className="pt-12 pb-2 text-7xl md:text-8xl xs:text-6xl font-extrabold max-w-4xl leading-tight xl:whitespace-nowrap md:whitespace-nowrap ">
7568
Don't Swipe. <span id="typewriter"></span><span id="cursor" className="animate-pulse">|</span>
7669
</h1>
7770
{/*<p className="mt-6 text-lg md:text-xl text-gray-400 max-w-2xl">*/}
7871
{/* {"Tired of swiping? Search what you're looking for!"}*/}
7972
{/*</p>*/}
8073
{/* Spacer */}
8174
<div className="h-10"></div>
82-
<div className="py-18">
83-
<Link href="/register" className={`${fontStyle} bg-gradient-to-r from-red-600 to-red-800 text-white rounded-full hover:from-red-700 hover:to-red-900`}>
75+
<div className="py-8">
76+
<Link href="/register"
77+
className={`${fontStyle} bg-gradient-to-r from-red-600 to-red-800 text-white rounded-full hover:from-red-700 hover:to-red-900`}>
8478
Join Compass
85-
8679
</Link>
87-
{/* Spacer */}
88-
<div className="h-52"></div>
80+
{/* Spacer */}
81+
{/*<div className="h-16"></div>*/}
8982
</div>
9083
{/* Why Compass Bar */}
91-
<div className="w-full bg-gray-50 dark:bg-gray-900 py-16 mt-20">
84+
<div className="w-full bg-gray-50 dark:bg-gray-900 py-8 mt-20">
9285
<div className="max-w-6xl mx-auto px-4">
9386
<div className="grid md:grid-cols-3 gap-8 text-center">
9487
<div className="space-y-2">
@@ -97,14 +90,14 @@ React.useEffect(() => {
9790
No algorithms. Every profile searchable.
9891
</p>
9992
</div>
100-
93+
10194
<div className="space-y-2">
10295
<h3 className="text-lg font-bold">Built for Depth</h3>
10396
<p className="text-gray-600 dark:text-gray-400">
10497
Filter by any keyword and what matters most.
10598
</p>
10699
</div>
107-
100+
108101
<div className="space-y-2">
109102
<h3 className="text-lg font-bold">Community Owned</h3>
110103
<p className="text-gray-600 dark:text-gray-400">
@@ -115,10 +108,16 @@ React.useEffect(() => {
115108
</div>
116109
</div>
117110
{/* Spacer */}
118-
<div className="h-20"></div>
119-
<div className=" w-full py-18">
120-
{profilePage()}
121-
</div>
111+
{userId &&
112+
<>
113+
{/*<div className="h-20"></div>*/}
114+
<div className=" w-full py-10">
115+
<main className="min-h-screen flex flex-col">
116+
<ProfilePage/>
117+
</main>
118+
</div>
119+
</>
120+
}
122121
</section>
123122
</main>
124123
);

app/profiles/page.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {useCallback, useEffect, useState} from "react";
55
import {DropdownKey, ProfileData} from "@/lib/client/schema";
66
import {dropdownConfig, ProfileFilters} from "./ProfileFilters";
77
import Image from "next/image";
8+
import {useSession} from "next-auth/react";
89

910
// Disable static generation
1011
export const dynamic = "force-dynamic";
@@ -41,6 +42,12 @@ type ProfileFilters = {
4142

4243

4344
export default function ProfilePage() {
45+
const {data: session} = useSession();
46+
const userId = session?.user?.id
47+
console.log("session:", userId)
48+
49+
// if (!userId) return <div/>
50+
4451
const [profiles, setProfiles] = useState<ProfileData[]>([]);
4552
const [loading, setLoading] = useState(true);
4653
const [error, setError] = useState('');
@@ -63,8 +70,7 @@ export default function ProfilePage() {
6370
if (key === 'searchQuery') {
6471
setText(value);
6572
newFilters[filterKey] = value as never;
66-
}
67-
else if (['interests', 'coreValues', 'causeAreas', 'connections'].includes(key)) {
73+
} else if (['interests', 'coreValues', 'causeAreas', 'connections'].includes(key)) {
6874
const arrayKey = filterKey as 'interests' | 'coreValues' | 'causeAreas' | 'connections';
6975
newFilters[arrayKey] = [...newFilters[arrayKey], value];
7076
} else {
@@ -182,6 +188,8 @@ export default function ProfilePage() {
182188

183189
const onFilterChange = handleFilterChange
184190

191+
if (!userId) return <div/>
192+
185193
return (
186194
<div className="min-h-screen px-4 sm:px-6 lg:px-8">
187195
<div className="w-full max-w-7xl mx-auto">

app/register/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Link from "next/link";
55
import {signIn} from "next-auth/react";
66
import {FcGoogle} from "react-icons/fc";
77
import {useSearchParams} from "next/navigation";
8-
import Image from "next/image";
8+
import {favIcon} from "@/lib/client/media";
99

1010

1111
export default function RegisterPage() {
@@ -149,7 +149,7 @@ function RegisterComponent() {
149149
{/* The project is still in development...*/}
150150
{/*</h2>*/}
151151
<div className="flex justify-center mb-6">
152-
<Image src="/favicon.ico" alt="Compass logo" className="w-24 h-24 dark:invert" />
152+
{favIcon()}
153153
</div>
154154
<h2 className="text-center text-3xl font-extrabold ">
155155
Get Started

0 commit comments

Comments
 (0)