Skip to content
9 changes: 1 addition & 8 deletions frontend/src/components/AuthGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from "react";
import { message } from "antd";
import { LoginDialog } from "@/pages/Layout/LoginDialog";
import { SignupDialog } from "@/pages/Layout/SignupDialog";
import { post, get } from "@/utils/request";
import { post } from "@/utils/request";
import { useTranslation } from "react-i18next";

function loginUsingPost(data: { username: string; password: string }) {
Expand Down Expand Up @@ -39,13 +39,6 @@ export function AuthGuard() {
};
}, [openLoginDialog]);

useEffect(() => {
const session = localStorage.getItem("session");
if (!session) {
get("/api/sys-param/sys.home.page.url").catch(() => {});
}
}, []);

const handleLogin = async (values: { username: string; password: string }) => {
try {
setLoading(true);
Expand Down
33 changes: 1 addition & 32 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@ import theme from "./theme";
import {errorConfigStore} from "@/utils/errorConfigStore.ts";
import "@/i18n";

async function checkHomePageRedirect(): Promise<string | null> {
try {
const response = await fetch('/api/sys-param/sys.home.page.url', {
cache: 'no-store'
});

if (response.ok) {
const result = await response.json();
return result.data?.paramValue?.trim() || null;
}
} catch (error) {
console.error('Failed to fetch home page URL:', error);
}

return null;
}

function showLoadingUI() {
const container = document.getElementById("root");
if (!container) return;
Expand Down Expand Up @@ -67,21 +50,7 @@ async function bootstrap() {
showLoadingUI();

try {
const [, homePageUrl] = await Promise.all([
errorConfigStore.loadConfig(),
checkHomePageRedirect()
]);

if (homePageUrl) {
const currentPath = window.location.pathname;
const targetPath = new URL(homePageUrl, window.location.origin).pathname;

if (currentPath === '/' && currentPath !== targetPath) {
window.location.href = homePageUrl;
return;
}
}

await errorConfigStore.loadConfig();
} catch (e) {
console.error('Config load failed:', e);
}
Expand Down
44 changes: 2 additions & 42 deletions frontend/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,19 @@ import {
Sparkles,
} from "lucide-react";
import { features, menuItems } from "../Layout/Menu.tsx";
import { useState, useEffect } from 'react';
import { useState } from 'react';
import { useNavigate } from "react-router";
import { Card, Dropdown, Button, Spin } from "antd";
import { Card, Dropdown, Button } from "antd";
import type { MenuProps } from 'antd';
import { Globe } from "lucide-react";
import { useTranslation } from "react-i18next";
import i18n from "@/i18n";
import { getHomePageUrl } from '@/utils/systemParam';

export default function WelcomePage() {
const navigate = useNavigate();
const [isChecking, setIsChecking] = useState(false);
const [isCheckingRedirect, setIsCheckingRedirect] = useState(true);
const { t } = useTranslation();

useEffect(() => {
let isMounted = true;

const checkAndRedirect = async () => {
try {
const homePageUrl = await getHomePageUrl();

if (!isMounted) return;

if (homePageUrl) {
window.location.href = homePageUrl;
return;
}

setIsCheckingRedirect(false);
} catch (error) {
console.error('Failed to check home page URL:', error);
if (isMounted) {
setIsCheckingRedirect(false);
}
}
};

checkAndRedirect();

return () => {
isMounted = false;
};
}, []);

if (isCheckingRedirect) {
return (
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center">
<Spin size="large" />
</div>
);
}

const languageMenuItems: MenuProps['items'] = [
{
key: 'zh',
Expand Down
Loading