feat: 用户名密码登录注册系统
- 新增 /api/auth/register 和 /api/auth/login 接口,使用 bcryptjs 哈希密码 - User 模型改为 username + passwordHash,id 自动生成 cuid - 新增 AuthModal 组件(登录/注册双标签页),替换旧的 ProfileSetupModal - 重写 /profile 页面:支持修改用户名、密码、头像、绑定邮箱、退出登录 - /api/user PUT 支持密码修改(需验证当前密码)和用户名唯一性校验 - 游客模式保留,右上角显示"登录"按钮;登录后显示头像和用户名 - 全局 nickname -> username 重命名(types、SwipeDeck、RoomManageModal、buildRoomStatus) - 新增 logout() 清除登录态并重新生成游客 UUID
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback } from "react";
|
||||
import { Star, MapPin, Clock, ExternalLink, Flame } from "lucide-react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { Star, MapPin, Clock, ExternalLink, Flame, Bookmark } from "lucide-react";
|
||||
import { Restaurant } from "@/types";
|
||||
import { getUserId, isRegistered } from "@/lib/userId";
|
||||
|
||||
interface RestaurantCardProps {
|
||||
restaurant: Restaurant;
|
||||
@@ -14,6 +15,22 @@ function stopAll(e: React.SyntheticEvent) {
|
||||
}
|
||||
|
||||
export default function RestaurantCard({ restaurant, likeCount = 0 }: RestaurantCardProps) {
|
||||
const [favorited, setFavorited] = useState(false);
|
||||
|
||||
const handleFavorite = useCallback(async (e: React.MouseEvent | React.TouchEvent) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
if (favorited) return;
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/user/favorite", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ userId: getUserId(), restaurant }),
|
||||
});
|
||||
if (res.ok) setFavorited(true);
|
||||
} catch {}
|
||||
}, [restaurant, favorited]);
|
||||
const openLink = useCallback(
|
||||
(url: string) => (e: React.MouseEvent | React.TouchEvent) => {
|
||||
e.stopPropagation();
|
||||
@@ -59,6 +76,20 @@ export default function RestaurantCard({ restaurant, likeCount = 0 }: Restaurant
|
||||
{restaurant.name}
|
||||
</h2>
|
||||
<div className="mt-0.5 flex shrink-0 gap-1.5">
|
||||
{isRegistered() && (
|
||||
<button
|
||||
onClick={handleFavorite}
|
||||
onPointerDown={stopAll}
|
||||
onTouchStart={stopAll}
|
||||
className={`flex items-center justify-center rounded-full p-1 transition-colors ${
|
||||
favorited
|
||||
? "bg-amber-100 text-amber-500"
|
||||
: "bg-zinc-50 text-zinc-400 active:bg-amber-50 active:text-amber-500"
|
||||
}`}
|
||||
>
|
||||
<Bookmark size={13} className={favorited ? "fill-amber-400" : ""} />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={openLink(amapUrl)}
|
||||
onPointerDown={stopAll}
|
||||
|
||||
Reference in New Issue
Block a user