feat: global login dialog with useRequireAuth hook for 401 auth gating
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { Heart } from "lucide-react"
|
||||
import { useState } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { useRequireAuth } from "@/lib/use-require-auth"
|
||||
|
||||
interface FavoriteButtonProps {
|
||||
initialFavorited: boolean
|
||||
@@ -10,13 +11,14 @@ interface FavoriteButtonProps {
|
||||
|
||||
export function FavoriteButton({ initialFavorited }: FavoriteButtonProps) {
|
||||
const [favorited, setFavorited] = useState(initialFavorited)
|
||||
const { requireAuth } = useRequireAuth()
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant={favorited ? "default" : "outline"}
|
||||
size="sm"
|
||||
className="gap-1.5"
|
||||
onClick={() => setFavorited(!favorited)}
|
||||
onClick={() => requireAuth(() => setFavorited(!favorited))}
|
||||
>
|
||||
<Heart className={`h-4 w-4 ${favorited ? "fill-current" : ""}`} />
|
||||
{favorited ? "已收藏" : "收藏"}
|
||||
|
||||
Reference in New Issue
Block a user