diff --git a/app/api/me/route.ts b/app/api/me/route.ts new file mode 100644 index 0000000..83b6282 --- /dev/null +++ b/app/api/me/route.ts @@ -0,0 +1,17 @@ +import { NextResponse } from "next/server"; +import { cookies } from "next/headers"; + +export async function GET() { + const cookieStore = await cookies(); + const auth = cookieStore.get("auth"); + if (!auth) { + return NextResponse.json({ isLoggedIn: false }); + } + + try { + const user = JSON.parse(auth.value); + return NextResponse.json(user); + } catch { + return NextResponse.json({ isLoggedIn: false }); + } +} diff --git a/app/auth/AuthClient.tsx b/app/auth/AuthClient.tsx new file mode 100644 index 0000000..51b9735 --- /dev/null +++ b/app/auth/AuthClient.tsx @@ -0,0 +1,39 @@ +"use client"; +import { useState } from "react"; +import LoginForm from "@/components/auth/login/LoginForm"; +import SignUpForm from "@/components/auth/signup/SignupForm"; + +export default function AuthClient() { + const [activeTab, setActiveTab] = useState<"signup" | "login">("signup"); + + return ( +
+
+
+ + +
+ + {activeTab === "signup" ? : } +
+
+ ); +} diff --git a/app/auth/page.tsx b/app/auth/page.tsx index 6a13db1..3d7e6c7 100644 --- a/app/auth/page.tsx +++ b/app/auth/page.tsx @@ -1,91 +1,12 @@ -"use client"; - -import { useState } from "react"; -import EmployeeSignUpForm from "@/components/employee/signup/SignupForm"; -import EmployeeLoginForm from "@/components/employee/login/LoginForm"; -import OrganizationSignUpForm from "@/components/organization/signup/SignupForm"; -import OrganizationLoginForm from "@/components/organization/login/LoginForm"; - -export default function Auth() { - const [activeTab, setActiveTab] = useState("signup"); - const [accountType, setAccountType] = useState("employee"); - - return ( -
-
-
- {/* Account Type Tabs */} -
- - -
- - {/* Login/Signup Toggle */} -
- - -
- - {/* Forms */} -
- {/* Employee Sign Up Form */} - {activeTab === "signup" && accountType === "employee" && ( - - )} - - {/* Employee Login Form */} - {activeTab === "login" && accountType === "employee" && ( - - )} - - {/* Organization Sign Up Form */} - {activeTab === "signup" && accountType === "organization" && ( - - )} - - {/* Organization Login Form */} - {activeTab === "login" && accountType === "organization" && ( - - )} -
-
-
-
- ); +// app/auth/page.tsx +import { redirect } from "next/navigation"; +import { getAuthUser } from "@/lib/auth"; +import AuthClient from "./AuthClient"; + +export default async function AuthPage() { + const user = await getAuthUser(); + if (user) { + redirect(`/dashboard`); + } + return ; } diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 9828d7b..45a306c 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -1,17 +1,18 @@ -export default function Dashboard() { +import { redirect } from "next/navigation"; +import { getAuthUser } from "@/lib/auth"; +import LogoutButton from "@/components/auth/logout/LogoutButton"; + +export default async function DashboardPage() { + const user = await getAuthUser(); + if (!user) { + redirect("/auth"); + } + return (
-

Dashboard

-
-
-

Welcome to your dashboard!

-
-
-
-
-

Here you can manage your account.

-
-
+

Welcome, {user.firstname || user.email}

+

Organisation: {user.organisationName}

+
); } diff --git a/app/layout.tsx b/app/layout.tsx index 6fdffc6..868de58 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,6 +3,7 @@ import { Inter } from "next/font/google"; import "./globals.css"; import AuthHeader from "@/components/AuthHeader"; import Footer from "@/components/Footer"; +import { AuthProvider } from "@/context/AuthContext"; const inter = Inter({ subsets: ["latin"] }); @@ -19,9 +20,11 @@ export default function RootLayout({ return ( - -
{children}
-