Download tasks/linkedin/tests/oracle-runtime/clone/lib/client-session.ts from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 787 Bytes
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/linkedin/tests/oracle-runtime/clone/lib/client-session.ts
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/linkedin/tests/oracle-runtime/clone/lib/client-session.ts
-
curl -L -o client-session.ts https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/linkedin/tests/oracle-runtime/clone/lib/client-session.ts
787 Bytes
| "use client"; | |
| import { useEffect, useState } from "react"; | |
| import { currentUser } from "./demo-data"; | |
| export type SessionUser = { | |
| id: string; | |
| email?: string; | |
| username: string; | |
| name: string; | |
| headline: string; | |
| avatarUrl?: string | null; | |
| }; | |
| export function useCurrentUser() { | |
| const [user, setUser] = useState<SessionUser>({ | |
| ...currentUser, | |
| avatarUrl: currentUser.avatar, | |
| }); | |
| useEffect(() => { | |
| let active = true; | |
| void fetch("/api/auth/session", { cache: "no-store" }) | |
| .then(async (response) => { | |
| const body = await response.json() as { user?: SessionUser | null }; | |
| if (active && response.ok && body.user) setUser(body.user); | |
| }) | |
| .catch(() => undefined); | |
| return () => { active = false; }; | |
| }, []); | |
| return user; | |
| } | |