Something went wrong. Try again.
A lexicon-driven AppView for ATProto.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334import { useCallback, useEffect, useState } from "react";
import { useAuth } from "@/lib/auth-context";import { getUsers } from "@/lib/api";import type { UserSummary } from "@/types/users";
export function useCurrentUser() { const { did } = useAuth(); const [currentUser, setCurrentUser] = useState<UserSummary | null>(null); const [loading, setLoading] = useState(true);
const load = useCallback(() => { setLoading(true); getUsers() .then((users) => setCurrentUser(users.find((u) => u.did === did) ?? null)) .catch(() => setCurrentUser(null)) .finally(() => setLoading(false)); }, [did]);
useEffect(() => { load(); }, [load]);
const isSuper = currentUser?.is_super ?? false;
const hasPermission = useCallback( (permission: string) => isSuper || (currentUser?.permissions.includes(permission) ?? false), [currentUser, isSuper], );
return { currentUser, isSuper, hasPermission, loading, reload: load };}