diff --git a/src/app/favicon.ico b/src/app/favicon.ico index 718d6fe..73b950e 100644 Binary files a/src/app/favicon.ico and b/src/app/favicon.ico differ diff --git a/src/middleware.ts b/src/middleware.ts index 00a0765..3d5ff3f 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -21,9 +21,9 @@ export function middleware(request: NextRequest) { // const selectedLocale = match(languages, locales, defaultLocale); // console.log('languages', languages, selectedLocale) // 如果用户已登录,且访问的是登录页面,则重定向到创建页面 - if (sessionid && pathname === '/login') { - return NextResponse.redirect(new URL('/create', request.url)); - } + // if (sessionid && pathname === '/login') { + // return NextResponse.redirect(new URL('/create', request.url)); + // } // 查找当前路径是否需要认证 const route = routes.find(route => pathname === route.path); diff --git a/src/ui/(console)/side-bar.tsx b/src/ui/(console)/side-bar.tsx index 94fb8a8..033bf7a 100644 --- a/src/ui/(console)/side-bar.tsx +++ b/src/ui/(console)/side-bar.tsx @@ -4,18 +4,17 @@ import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import React, { useState } from "react"; import Image from "next/image"; -import logoImage from "/public/images/logo2.png"; + import { FaPlus, FaBars } from "react-icons/fa6"; import { MdOutlineHome, MdLogout } from "react-icons/md"; import { PiSquaresFourBold } from "react-icons/pi"; import { BsLightningChargeFill } from "react-icons/bs"; -import { useTranslations } from "next-intl"; +import { useTranslations, useLocale } from "next-intl"; import classNames from "classnames"; import useUserStore from "@/store/userStore"; import useFetch from "@/hooks/useFetch"; import { useToast } from "@/contexts/ToastContext"; import useLoadingStore from "@/store/loadingStore"; - type MenuItem = { name: string; href: string; @@ -27,6 +26,8 @@ export default function SideBar() { const router = useRouter(); const user = useUserStore((state) => state.user); const t = useTranslations("sideBar"); + const locale = useLocale(); + const { addToast, addToastSuccess, addToastError } = useToast(); const [sidebarOpen, setSidebarOpen] = useState(false); // 控制侧边栏的开关状态 const hideLoading = useLoadingStore((state) => state.hideLoading); @@ -52,24 +53,20 @@ export default function SideBar() { loading: logoutLoading, data: logoutResult, } = useFetch({ - url: "/api/logout/", // 假设你的退出接口路径为 /api/logout/ + url: "/api/logout/", // 假设你的退出接口路径为 /api/logout/ method: "POST", }); - - const logout = () => { - logoutFetch() // 不需要传递参数 + const logout = () => { + logoutFetch() // 不需要传递参数 .then((res) => { addToastSuccess(t("logoutSuccess")); - router.push("/login"); // 退出成功后跳转到登录页面 + router.push("/login"); // 退出成功后跳转到登录页面 }) .finally(() => { hideLoading(); }); }; - - - return (
@@ -94,16 +91,21 @@ export default function SideBar() { style={{ width: "240px" }} > {/* 侧边栏内容 */} -
- +
+ typeframes.ai logo
@@ -199,4 +201,3 @@ export default function SideBar() {
); } - diff --git a/src/ui/login/google-login.tsx b/src/ui/login/google-login.tsx index 1657a04..5364197 100644 --- a/src/ui/login/google-login.tsx +++ b/src/ui/login/google-login.tsx @@ -2,31 +2,54 @@ import useFetch from "@/hooks/useFetch"; import { useTranslations } from "next-intl"; import { useState } from "react"; + export default function GoogleLogin() { const t = useTranslations("loginForm"); + const [loading, setLoading] = useState(false); // 添加 loading 状态 - const { fetchData: fetchGoogleLogin, loading: loading } = useFetch({ - url: "/oauth2callback/google/login", - method: "POST", - }); - const googleLogin = () => { - fetchGoogleLogin(); + const googleLogin = async (method: string) => { + setLoading(true); // 开始请求时设置 loading 为 true + try { + const response = await fetch("/oauth2callback/google/login/", { + method: method, + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + }); + console.log("response", response); + if (response.ok) { + console.log("Success:", response); + window.location.href = response.url; + // 处理成功响应 + } else { + console.error("Failed:", response.status); + // 处理失败响应 + } + } catch (error) { + console.error("Error:", error); + // 处理请求错误 + } finally { + setLoading(false); // 请求结束后设置 loading 为 false + } }; return ( ); diff --git a/src/ui/page/page-header.tsx b/src/ui/page/page-header.tsx index b94b857..357ef8d 100644 --- a/src/ui/page/page-header.tsx +++ b/src/ui/page/page-header.tsx @@ -1,10 +1,10 @@ import Image from "next/image"; -import { useTranslations } from "next-intl"; +import { useTranslations, useLocale } from "next-intl"; -import logoImage from "/public/images/logo.png"; import Link from "next/link"; export default function PageHeader() { const t = useTranslations("pageHeader"); + const locale = useLocale(); return (