diff --git a/frontend/index.html b/frontend/index.html index c27651a..54219dd 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -6,7 +6,7 @@ - + The VoD System diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx index bb33d56..32d1f0e 100644 --- a/frontend/src/components/Sidebar.tsx +++ b/frontend/src/components/Sidebar.tsx @@ -1,27 +1,50 @@ import clsx from "clsx"; import SidebarButton from "./buttons/SidebarButton.tsx"; -import { Plus, Film, Home, User as UserIcon, Video, Radio } from 'lucide-react'; -import type {User} from "../utils/types.ts"; +import { Plus, Film, Home, Video, Radio } from 'lucide-react'; +import {useAuth} from "../utils/AuthContext.tsx"; +import {type CredentialResponse, GoogleLogin} from "@react-oauth/google"; +import {getUser, login, logout} from "../utils/api/users.ts"; type props = { - user: User | null; className?: string } -const Divider = () =>
; +const Divider = () =>
; + +const Sidebar = ({ className }: props) => { + const { user, setUser } = useAuth() + + const handleLogin = (response: CredentialResponse) => { + if (!response.credential) { + console.error("No credential received from Google login."); + return; + } + + login(response.credential) + .then(() => { + getUser().then(userData => setUser(userData)) + }) + .catch((error) => { + console.error("Login failed:", error); + }); + } + const handleLogout = () => { + logout() + .then(() => + setUser(null) + ) + .catch((error) => { + console.error("Logout failed:", error); + }); + } -const Sidebar = ({user, className}: props) => { return ( -