diff --git a/app/[locale]/(main)/header.tsx b/app/[locale]/(main)/header.tsx index cb335a9..82177d0 100644 --- a/app/[locale]/(main)/header.tsx +++ b/app/[locale]/(main)/header.tsx @@ -63,7 +63,7 @@ function Header() { // https://github.com/streamich/react-use/blob/master/src/useInterval.ts const useInterval = (callback: Function, delay?: number | null) => { - const savedCallback = useRef(() => { }); + const savedCallback = useRef(() => {}); useEffect(() => { savedCallback.current = callback; }); @@ -98,7 +98,9 @@ function Overview() {

{mouted ? (

{timeString}

- ) : } + ) : ( + + )} ); diff --git a/app/[locale]/(main)/layout.tsx b/app/[locale]/(main)/layout.tsx index bb2a8de..e60a237 100644 --- a/app/[locale]/(main)/layout.tsx +++ b/app/[locale]/(main)/layout.tsx @@ -1,7 +1,7 @@ import Footer from "@/app/[locale]/(main)/footer"; import Header from "@/app/[locale]/(main)/header"; import { auth } from "@/auth"; -import { SignIn } from "@/components/sign-in"; +import { SignIn } from "@/components/SignIn"; import getEnv from "@/lib/env-entry"; import { redirect } from "next/navigation"; import React from "react"; @@ -13,11 +13,7 @@ export default async function MainLayout({ children }: DashboardProps) { const session = await auth(); if (!session && getEnv("SitePassword")) { - if (getEnv("CF_PAGES")) { - redirect("/api/auth/signin"); - } else { - return ; - } + return ; } return ( diff --git a/auth.ts b/auth.ts index dea71d1..dc90f57 100644 --- a/auth.ts +++ b/auth.ts @@ -6,14 +6,15 @@ import getEnv from "./lib/env-entry"; export const { handlers, signIn, signOut, auth } = NextAuth({ secret: "this_is_nezha_dash_web_secret", trustHost: true, + pages: { + signIn: "/", + }, providers: [ Credentials({ - credentials: { - password: {}, - }, + credentials: { password: { label: "Password", type: "password" } }, authorize: async (credentials) => { if (credentials.password === getEnv("SitePassword")) { - return { id: "0" }; + return { id: "nezha-dash-auth" }; } return null; }, diff --git a/components/SignIn.tsx b/components/SignIn.tsx new file mode 100644 index 0000000..272c47c --- /dev/null +++ b/components/SignIn.tsx @@ -0,0 +1,66 @@ +"use client"; + +import Footer from "@/app/[locale]/(main)/footer"; +import Header from "@/app/[locale]/(main)/header"; +import { getCsrfToken } from "next-auth/react"; +import { useTranslations } from "next-intl"; +import { useSearchParams } from "next/navigation"; +import { useEffect, useState } from "react"; + +export function SignIn({}) { + const t = useTranslations("SignIn"); + + const [csrfToken, setCsrfToken] = useState(""); + const [errorState, setErrorState] = useState(false); + + const search = useSearchParams(); + const error = search.get("error"); + + useEffect(() => { + if (error) { + setErrorState(true); + } + }, [error]); + + useEffect(() => { + async function loadProviders() { + const csrf = await getCsrfToken(); + setCsrfToken(csrf); + } + loadProviders(); + }, []); + + return ( +
+
+
+
+ +
+ + +
+
+
+
+
+ ); +} diff --git a/components/sign-in.tsx b/components/sign-in.tsx deleted file mode 100644 index c8adbea..0000000 --- a/components/sign-in.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import Footer from "@/app/[locale]/(main)/footer"; -import Header from "@/app/[locale]/(main)/header"; -import { signIn } from "@/auth"; -import { useLocale } from "next-intl"; -import { redirect } from "next/navigation"; - -export function SignIn() { - const locale = useLocale(); - - async function handleSubmit(formData: FormData) { - "use server"; - try { - await signIn("credentials", formData); - } catch (error) { - redirect(`/${locale}`); - } - } - - return ( -
-
-
-
-
- - -
-
-
-
- ); -} diff --git a/messages/en.json b/messages/en.json index 0fe32f9..49e7536 100644 --- a/messages/en.json +++ b/messages/en.json @@ -23,6 +23,11 @@ "Detail": "Detail", "Network": "Network" }, + "SignIn": { + "SignInMessage": "Please enter the password", + "Submit": "Login", + "ErrorMessage": "Invalid password" + }, "ServerCardPopover": { "System": "System", "CPU": "CPU", diff --git a/messages/ja.json b/messages/ja.json index 02aef43..d89e131 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -23,6 +23,11 @@ "Detail": "詳細", "Network": "ネットワーク" }, + "SignIn": { + "SignInMessage": "パスワードを入力してください", + "Submit": "ログイン", + "ErrorMessage": "パスワードが間違っています" + }, "ServerCardPopover": { "System": "システム", "CPU": "CPU", diff --git a/messages/zh-t.json b/messages/zh-t.json index ffead2a..b1bee23 100644 --- a/messages/zh-t.json +++ b/messages/zh-t.json @@ -23,6 +23,11 @@ "Detail": "詳細", "Network": "網路" }, + "SignIn": { + "SignInMessage": "請輸入密碼", + "Submit": "登入", + "ErrorMessage": "密碼錯誤" + }, "ServerCardPopover": { "System": "系統", "CPU": "CPU", diff --git a/messages/zh.json b/messages/zh.json index ed853f0..2786dad 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -23,6 +23,11 @@ "Detail": "详情", "Network": "网络" }, + "SignIn": { + "SignInMessage": "请输入密码", + "Submit": "登录", + "ErrorMessage": "密码错误" + }, "ServerCardPopover": { "System": "系统", "CPU": "CPU", diff --git a/next.config.mjs b/next.config.mjs index a68be47..86bfbf5 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -23,11 +23,6 @@ const withPWA = withPWAInit({ const nextConfig = { output: "standalone", reactStrictMode: true, - experimental: { - serverActions: { - allowedOrigins: ["*"], - }, - }, logging: { fetches: { fullUrl: true,