fix: hydration

This commit is contained in:
shinya
2025-07-25 19:11:40 +08:00
parent ac1cd7b148
commit e4c0fe690f

View File

@@ -3,7 +3,7 @@
'use client'; 'use client';
import { useRouter, useSearchParams } from 'next/navigation'; import { useRouter, useSearchParams } from 'next/navigation';
import { Suspense, useState } from 'react'; import { Suspense, useEffect, useState } from 'react';
import { useSite } from '@/components/SiteProvider'; import { useSite } from '@/components/SiteProvider';
import { ThemeToggle } from '@/components/ThemeToggle'; import { ThemeToggle } from '@/components/ThemeToggle';
@@ -15,18 +15,20 @@ function LoginPageClient() {
const [username, setUsername] = useState(''); const [username, setUsername] = useState('');
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [shouldAskUsername, setShouldAskUsername] = useState(false);
const [enableRegister, setEnableRegister] = useState(false);
const { siteName } = useSite(); const { siteName } = useSite();
// 当 STORAGE_TYPE 不为空且不为 localstorage 时,要求输入用户名 // 在客户端挂载后设置配置
const shouldAskUsername = useEffect(() => {
typeof window !== 'undefined' && if (typeof window !== 'undefined') {
(window as any).RUNTIME_CONFIG?.STORAGE_TYPE && const storageType = (window as any).RUNTIME_CONFIG?.STORAGE_TYPE;
(window as any).RUNTIME_CONFIG?.STORAGE_TYPE !== 'localstorage'; setShouldAskUsername(storageType && storageType !== 'localstorage');
setEnableRegister(
// 是否允许注册 Boolean((window as any).RUNTIME_CONFIG?.ENABLE_REGISTER)
const enableRegister = );
typeof window !== 'undefined' && }
Boolean((window as any).RUNTIME_CONFIG?.ENABLE_REGISTER); }, []);
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault(); e.preventDefault();