fix: 优化图片上传URL和房东入口登录检查体验
This commit is contained in:
@@ -25,7 +25,9 @@ export async function POST(request: NextRequest) {
|
|||||||
const buffer = await file.arrayBuffer();
|
const buffer = await file.arrayBuffer();
|
||||||
await fs.writeFile(filepath, Buffer.from(buffer));
|
await fs.writeFile(filepath, Buffer.from(buffer));
|
||||||
|
|
||||||
const url = `/uploads/${filename}`;
|
const host = request.headers.get('host') || 'localhost:3000';
|
||||||
|
const protocol = request.headers.get('x-forwarded-proto') || 'http';
|
||||||
|
const url = `${protocol}://${host}/uploads/${filename}`;
|
||||||
return NextResponse.json({ url });
|
return NextResponse.json({ url });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Upload error:', error);
|
console.error('Upload error:', error);
|
||||||
|
|||||||
@@ -11,23 +11,45 @@ export default function OwnerPage() {
|
|||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [user, setUser] = useState<{ username: string } | null>(null);
|
const [checking, setChecking] = useState(true);
|
||||||
|
const [ready, setReady] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
checkAuth();
|
let cancelled = false;
|
||||||
}, []);
|
|
||||||
|
|
||||||
async function checkAuth() {
|
async function checkAuth() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/auth/me");
|
const res = await fetch("/api/auth/me");
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.user) {
|
if (!cancelled && data.user) {
|
||||||
setUser(data.user);
|
router.replace("/owner/dashboard");
|
||||||
router.push("/owner/dashboard");
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("检查登录状态失败", error);
|
||||||
|
}
|
||||||
|
if (!cancelled) {
|
||||||
|
setChecking(false);
|
||||||
|
setReady(true);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error("检查登录状态失败", error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkAuth();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
if (!ready) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
||||||
|
<div className="text-center">
|
||||||
|
<div className="text-4xl mb-2 animate-bounce">🏗️</div>
|
||||||
|
<p className="text-gray-500">检查登录状态...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSubmit(e: React.FormEvent) {
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user