Added user authentication

This commit is contained in:
2026-07-14 12:59:47 -04:00
parent 5d6aa0a569
commit 6aab99ab8f
4 changed files with 109 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import { Tabs } from "@heroui/react";
import { Button } from "@heroui/react";
import { useNavigate, useLocation } from "react-router";
import porning from "../images/porning.svg";
import User from "./user";
export function Header() {
const location = useLocation();
@@ -42,7 +43,7 @@ export function Header() {
<div className="absolute flex left-1/2 -translate-x-1/2">
<img className="h-12" src={porning} alt="Porning logo" />
</div>
<Button>Login</Button>
<User />
</Surface>
</div>
);

40
app/components/user.tsx Normal file
View File

@@ -0,0 +1,40 @@
import { Button, Avatar, Typography, Dropdown, Label, Separator } from "@heroui/react";
import { useAuth } from "~/hooks/auth";
export default function User() {
const {user, login, logout} = useAuth();
if (user === null) {
return <Button onClick={() => login()}>Login</Button>;
}
return (
<Dropdown>
<Button className="pr-0">
<Typography.Paragraph>{user.name}</Typography.Paragraph>
<Avatar>
<Avatar.Image alt="Avatar" src={user.avatar}></Avatar.Image>
</Avatar>
</Button>
<Dropdown.Popover >
<Dropdown.Menu onAction={(key) => handleAction(String(key), logout)}>
<Dropdown.Item id="settings" textValue="Settings">
<Label>Settings</Label>
</Dropdown.Item>
<Separator variant="tertiary"/>
<Dropdown.Item id="logout" textValue="Logout" variant="danger">
<Label>Logout</Label>
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown.Popover>
</Dropdown>
);
}
function handleAction(key: string, logout: () => Promise<void>) {
if (key === "settings") {
console.log("settings");
} else {
logout();
}
}