mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-06 15:59:47 -05:00
Error api call if not logged in
This commit is contained in:
@@ -9,8 +9,11 @@ export async function GET() {
|
||||
const session = await getSession();
|
||||
console.log(`Session: ${session?.user?.name}`);
|
||||
|
||||
if (!session?.user?.email)
|
||||
redirect('/login');
|
||||
if (!session?.user?.id)
|
||||
return new NextResponse(JSON.stringify({ error: "User not found" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
|
||||
const id = session.user.id;
|
||||
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import {usePathname} from "next/navigation";
|
||||
import {usePathname, useRouter} from "next/navigation";
|
||||
import {getProfile} from "@/lib/client/profile";
|
||||
import {useEffect} from "react";
|
||||
import {useSession} from "next-auth/react";
|
||||
|
||||
export default function ProfilePage() {
|
||||
const pathname = usePathname(); // Get the current route
|
||||
const router = useRouter();
|
||||
const {data: session} = useSession();
|
||||
|
||||
useEffect(() => {
|
||||
async function asyncRun() {
|
||||
if (!session?.user?.id)
|
||||
router.push('/login');
|
||||
}
|
||||
|
||||
asyncRun();
|
||||
}, []);
|
||||
|
||||
try {
|
||||
|
||||
const header = (
|
||||
|
||||
Reference in New Issue
Block a user