Files
kino-app/frontend/src/lib/profile.jsx
T
Myron Blair f7626ced2e Merge watch profiles into user accounts — one profile per login, no picker
- Removed the "Who's Watching" sub-profile picker entirely: ProfileProvider now
  auto-resolves the single profile tied to the account immediately after login
- Backend: removed POST/DELETE /profiles (no more creating/deleting extra
  profiles — lifecycle is entirely driven by user create/delete, already wired
  in the admin Users CRUD); kept GET (internal) and PATCH (edit your own
  profile's avatar/kids-mode/rating cap)
- Deleted ProfileSelect page and the now-unused ProtectedRoute component
- Navbar: removed the "switch profile" action, account avatar is now just a
  static display
- api.js: dropped the now-dead X-Profile-Id header logic (backend already
  falls back to the account's single profile when the header is absent)
2026-07-26 19:40:12 -05:00

33 lines
860 B
React

import { createContext, useContext, useEffect, useState, useCallback } from "react";
import api from "./api";
import { useAuth } from "./auth";
const ProfileCtx = createContext(null);
export const ProfileProvider = ({ children }) => {
const { user } = useAuth();
const [active, setActive] = useState(null);
const [loading, setLoading] = useState(false);
const refresh = useCallback(async () => {
if (!user) { setActive(null); return; }
setLoading(true);
try {
const { data } = await api.get("/profiles");
setActive(data[0] || null);
} finally {
setLoading(false);
}
}, [user]);
useEffect(() => { refresh(); }, [refresh]);
return (
<ProfileCtx.Provider value={{ active, loading, refresh }}>
{children}
</ProfileCtx.Provider>
);
};
export const useProfile = () => useContext(ProfileCtx);