// pages/dashboard.js
'use client';
import { useEffect, useState } from "react";
import { account } from "../../lib/appwrite";
import { useRouter } from "next/navigation";

export default function Dashboard() {
  const [user, setUser] = useState(null);
  const router = useRouter();

  useEffect(() => {
    const checkAuth = async () => {
      try {
        const currentUser = await account.get();
        setUser(currentUser);
      } catch (err) {
        router.push("/");
      }
    };
    checkAuth();
  }, [router]);

  if (!user) {
    return <div className="p-4">Loading...</div>;
  }

  return (
    <div className="p-4">
      <h1>Welcome, {user.name}</h1>
     
    </div>
  );
}