mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-03-06 20:17:32 +08:00
fix: hydration
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user