diff --git a/app/api/server-setting/find_by_code/route.ts b/app/api/server-setting/find_by_code/route.ts new file mode 100644 index 0000000..dd178ae --- /dev/null +++ b/app/api/server-setting/find_by_code/route.ts @@ -0,0 +1,94 @@ +/** + * Server Setting API路由 + * 根据code获取服务端配置 + */ + +import { NextRequest, NextResponse } from 'next/server'; + +/** + * 根据code获取服务端配置 + * POST /api/server-setting/find_by_code + */ +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + const { code } = body; + + console.log('📋 获取服务端配置请求:', { code }); + + if (!code) { + return NextResponse.json({ + code: 400, + successful: false, + message: 'code parameter is required', + data: null + }, { status: 400 }); + } + + // 根据code返回不同的配置,匹配实际API格式 + let responseData = null; + + switch (code) { + case 'sso_config': + // SSO配置 - 控制Google登录按钮显示 + responseData = { + id: 8, + code: 'sso_config', + value: '{\n "show": true\n}', + note: 'sso 入口', + updated_at: new Date().toISOString().slice(0, 19) + }; + break; + + case 'home_tabs': + // 首页标签配置示例 + responseData = { + id: 1, + code: 'home_tabs', + value: JSON.stringify([ + { + id: '1', + title: '推荐', + subtitle: '为您推荐', + status: 1, + sortOrder: 1, + videos: [] + } + ], null, 2), + note: '首页标签配置', + updated_at: new Date().toISOString().slice(0, 19) + }; + break; + + default: + // 默认返回空配置 + responseData = { + id: 0, + code: code, + value: '{}', + note: '默认配置', + updated_at: new Date().toISOString().slice(0, 19) + }; + break; + } + + const response = { + code: 0, + successful: true, + message: 'Success', + data: responseData + }; + + console.log('✅ 服务端配置获取成功:', { code, hasData: !!responseData }); + return NextResponse.json(response); + + } catch (error) { + console.error('❌ 获取服务端配置失败:', error); + return NextResponse.json({ + code: 500, + successful: false, + message: 'Internal server error', + data: null + }, { status: 500 }); + } +} diff --git a/app/signup/page.tsx b/app/signup/page.tsx index b71829f..5b21eb2 100644 --- a/app/signup/page.tsx +++ b/app/signup/page.tsx @@ -7,6 +7,7 @@ import { signInWithGoogle, sendVerificationLink, registerUserWithInvite } from " import { GradientText } from "@/components/ui/gradient-text"; import { GoogleLoginButton } from "@/components/ui/google-login-button"; import { Eye, EyeOff, Mail } from "lucide-react"; +import { isGoogleLoginEnabled } from "@/lib/server-config"; export default function SignupPage() { const [name, setName] = useState(""); @@ -26,9 +27,10 @@ export default function SignupPage() { const [googleLoading, setGoogleLoading] = useState(false); const [emailFocused, setEmailFocused] = useState(false); const [passwordFocused, setPasswordFocused] = useState(false); + const [showGoogleLogin, setShowGoogleLogin] = useState(false); const router = useRouter(); - // Handle scroll indicator for small screens + // Handle scroll indicator for small screens and load SSO config React.useEffect(() => { try { const url = new URL(window.location.href); @@ -40,6 +42,20 @@ export default function SignupPage() { sessionStorage.setItem("inviteCode", code); } } catch (err) {} + + // 检查是否启用Google登录 + const checkGoogleLoginStatus = async () => { + try { + const enabled = await isGoogleLoginEnabled(); + setShowGoogleLogin(enabled); + } catch (error) { + console.error("Failed to check Google login status:", error); + setShowGoogleLogin(false); + } + }; + + checkGoogleLoginStatus(); + const handleScroll = () => { const scrollableElement = document.querySelector('.signup-form > div:nth-child(2)'); const formElement = document.querySelector('.signup-form'); @@ -493,21 +509,25 @@ export default function SignupPage() { {/* Fixed Footer */}
diff --git a/components/pages/login.tsx b/components/pages/login.tsx index 265a613..8defed2 100644 --- a/components/pages/login.tsx +++ b/components/pages/login.tsx @@ -9,6 +9,7 @@ import { signInWithGoogle, loginUser } from "@/lib/auth"; import { GradientText } from "@/components/ui/gradient-text"; import { GoogleLoginButton } from "@/components/ui/google-login-button"; import { Eye, EyeOff } from "lucide-react"; +import { isGoogleLoginEnabled } from "@/lib/server-config"; export default function Login() { const [email, setEmail] = useState(""); @@ -21,6 +22,7 @@ export default function Login() { const [googleLoading, setGoogleLoading] = useState(false); const [emailFocused, setEmailFocused] = useState(false); const [passwordFocused, setPasswordFocused] = useState(false); + const [showGoogleLogin, setShowGoogleLogin] = useState(false); const router = useRouter(); const searchParams = useSearchParams(); @@ -56,7 +58,7 @@ export default function Login() { } }; - // Check for registered=true parameter + // Check for registered=true parameter and load SSO config useEffect(() => { const registered = searchParams?.get("registered"); if (registered === "true") { @@ -77,6 +79,22 @@ export default function Login() { setFormError("The old OAuth method is deprecated. Please use the Google login button below for a better experience."); } } + + // 检查是否启用Google登录 + const checkGoogleLoginStatus = async () => { + try { + console.log('🔍 登录页面:开始检查Google登录状态...'); + const enabled = await isGoogleLoginEnabled(); + console.log('📋 登录页面:Google登录启用状态:', enabled); + setShowGoogleLogin(enabled); + console.log('📋 登录页面:设置showGoogleLogin状态为:', enabled); + } catch (error) { + console.error("❌ 登录页面:Failed to check Google login status:", error); + setShowGoogleLogin(false); + } + }; + + checkGoogleLoginStatus(); }, [searchParams]); const handleGoogleSignIn = async () => { @@ -262,21 +280,26 @@ export default function Login() { > {isSubmitting ? "Logging in..." : "Login"} - {/* 谷歌登录按钮已暂时注释 */} -
diff --git a/lib/server-config.ts b/lib/server-config.ts
new file mode 100644
index 0000000..c27e7e4
--- /dev/null
+++ b/lib/server-config.ts
@@ -0,0 +1,88 @@
+/**
+ * 服务端配置工具函数
+ */
+
+import { post } from '@/api/request';
+
+/**
+ * SSO配置接口
+ */
+export interface SSOConfig {
+ show: boolean;
+ provider: string;
+ displayName: string;
+ description: string;
+}
+
+/**
+ * 获取SSO配置
+ * @returns Promise