mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 22:14:08 +01:00
23 lines
596 B
TypeScript
23 lines
596 B
TypeScript
"use client";
|
|
|
|
import { useContext } from "react";
|
|
import { SessionContext } from "@/context/SessionContext";
|
|
|
|
export function useSession() {
|
|
const context = useContext(SessionContext);
|
|
if (!context) {
|
|
throw new Error("useSession must be used within a SessionProvider");
|
|
}
|
|
|
|
const { token, user, loading } = context;
|
|
let status: "loading" | "authenticated" | "unauthenticated";
|
|
|
|
if (loading) status = "loading";
|
|
else if (token) status = "authenticated";
|
|
else status = "unauthenticated";
|
|
|
|
const session = token ? { token, user } : null;
|
|
|
|
return { data: session, status };
|
|
}
|