From 648828d0aae4f08f6638f02f5342f2eb60fe5c9d Mon Sep 17 00:00:00 2001 From: GaoNeng <31283122+GaoNeng-wWw@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:37:32 +0800 Subject: [PATCH] fix: Fixed the issue of jumping to the dashboard before judging (#28) --- app/authenticate/page.tsx | 2 +- app/dashboard/page.tsx | 8 ++++++-- app/page.tsx | 4 +++- app/providers.tsx | 2 +- components/password.tsx | 6 +++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/authenticate/page.tsx b/app/authenticate/page.tsx index 9d58d96..7aa8f29 100644 --- a/app/authenticate/page.tsx +++ b/app/authenticate/page.tsx @@ -40,7 +40,7 @@ const Login = ( } const CheckCode = (props: {type: 'email' | 'phone' | 'unknown', userInput: string}) => { const {type} = props; - const [loading, setLoading] = useState(true); + const [loading, setLoading] = useState(false ); const [cd, setCD] = useState(1000) const [time, setTime] = useCountDown(cd) const getCode = () => { diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index f8207b6..295eec6 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -4,7 +4,7 @@ import Uploader from "@/components/uploader"; import {Card, CardBody, CardFooter, Divider} from "@nextui-org/react"; import {Progress} from "@nextui-org/progress"; import {Button} from "@nextui-org/button"; -import {useRouter} from "next/navigation"; +import {redirect, useRouter} from "next/navigation"; import {Chip} from "@nextui-org/chip"; import {FiChevronsUp, FiUploadCloud} from "react-icons/fi"; import Picture from "@/components/picture"; @@ -15,10 +15,14 @@ import {getGroupPrice} from "@/config/prices"; import {PictureList} from "@/interface/model/picture"; import {SERVER_URL} from "@/interface/api"; import cookie from "react-cookies"; -import {userInfo} from "os"; import {PriceInfo} from "@/components/price"; +import { IsLoggedIn } from "@/interface/hooks"; +import { RedirectType } from "next/dist/client/components/redirect"; export default function Page() { + if (!IsLoggedIn){ + redirect('/authenticate', RedirectType.replace); + } let [used, setUsed] = useState(0); let [total, setTotal] = useState(1); diff --git a/app/page.tsx b/app/page.tsx index e718012..328209a 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -30,8 +30,9 @@ export default function Home() {
开始使用 @@ -40,6 +41,7 @@ export default function Home() { as={NextLink} className={buttonStyles({variant: "bordered"})} href={siteConfig.navItems[2].href} + prefetch > 日志 diff --git a/app/providers.tsx b/app/providers.tsx index a72cb6a..028f593 100644 --- a/app/providers.tsx +++ b/app/providers.tsx @@ -33,7 +33,7 @@ export function AuthProvider({children, whiteList}: AuthProvider) { } }, [pathName, whiteList]) if (!IsLoggedIn && !whiteList.includes(pathName)){ - return null; + return <>; } return ( <> diff --git a/components/password.tsx b/components/password.tsx index c8d0aaf..6558e17 100644 --- a/components/password.tsx +++ b/components/password.tsx @@ -5,15 +5,15 @@ import { useState } from "react"; export interface PasswordProps { label: string; placeholder: string; - key: string value?: string; onValueChange?: (val:string)=>void; } export default function Password( - props: PasswordProps + props: PasswordProps, + key: string ){ - const {key, label, placeholder, value, onValueChange} = props + const {label, placeholder, value, onValueChange} = props const [visible, setVisible] = useState(false); const toggleVisible = () => setVisible(!visible); const endContent = () => {