Dev remove admin mode (#723)

* feat: remove admin mode
* feat: bugfix
---------
Co-authored-by: icy <icyoung520@gmail.com>
This commit is contained in:
Icyoung
2025-11-07 23:37:23 +08:00
committed by GitHub
parent 9ad3e99645
commit 062184054d
16 changed files with 160 additions and 180 deletions

View File

@@ -44,7 +44,7 @@ function getModelDisplayName(modelId: string): string {
function App() {
const { language, setLanguage } = useLanguage()
const { user, token, logout, isLoading } = useAuth()
const { config: systemConfig, loading: configLoading } = useSystemConfig()
const { loading: configLoading } = useSystemConfig()
const [route, setRoute] = useState(window.location.pathname)
// 从URL路径读取初始页面状态支持刷新保持页面
@@ -230,10 +230,6 @@ function App() {
return <LoginPage />
}
if (route === '/register') {
if (systemConfig?.admin_mode) {
window.history.pushState({}, '', '/login')
return <LoginPage />
}
return <RegisterPage />
}
if (route === '/faq') {
@@ -255,8 +251,7 @@ function App() {
onLanguageChange={setLanguage}
user={user}
onLogout={logout}
isAdminMode={systemConfig?.admin_mode}
onPageChange={(page) => {
onPageChange={(page) => {
console.log('Competition page onPageChange called with:', page)
console.log('Current route:', route, 'Current page:', currentPage)
@@ -298,16 +293,11 @@ function App() {
// Show landing page for root route
if (route === '/' || route === '') {
return <LandingPage isAdminMode={systemConfig?.admin_mode} />
return <LandingPage />
}
// In admin mode, require authentication for any protected routes
if (systemConfig?.admin_mode && (!user || !token)) {
return <LoginPage />
}
// Show main app for authenticated users on other routes (non-admin mode)
if (!systemConfig?.admin_mode && (!user || !token)) {
// Show main app for authenticated users on other routes
if (!user || !token) {
// Default to landing page when not authenticated and no specific route
return <LandingPage />
}
@@ -324,8 +314,7 @@ function App() {
onLanguageChange={setLanguage}
user={user}
onLogout={logout}
isAdminMode={systemConfig?.admin_mode}
onPageChange={(page) => {
onPageChange={(page) => {
console.log('Main app onPageChange called with:', page)
if (page === 'competition') {

View File

@@ -1,9 +1,8 @@
import React, { useEffect, useState } from 'react'
import React, { useState } from 'react'
import { useAuth } from '../contexts/AuthContext'
import { useLanguage } from '../contexts/LanguageContext'
import { t } from '../i18n/translations'
import HeaderBar from './landing/HeaderBar'
import { getSystemConfig } from '../lib/config'
export function LoginPage() {
const { language } = useLanguage()
@@ -16,17 +15,8 @@ export function LoginPage() {
const [error, setError] = useState('')
const [loading, setLoading] = useState(false)
const [adminPassword, setAdminPassword] = useState('')
const [adminMode, setAdminMode] = useState<boolean | null>(null)
const adminMode = false
useEffect(() => {
getSystemConfig()
.then((cfg) => {
setAdminMode(!!cfg.admin_mode)
})
.catch(() => {
setAdminMode(false)
})
}, [])
const handleAdminLogin = async (e: React.FormEvent) => {
e.preventDefault()

View File

@@ -12,7 +12,6 @@ interface HeaderBarProps {
onLanguageChange?: (lang: Language) => void
user?: { email: string } | null
onLogout?: () => void
isAdminMode?: boolean
onPageChange?: (page: string) => void
}
@@ -24,7 +23,6 @@ export default function HeaderBar({
onLanguageChange,
user,
onLogout,
isAdminMode = false,
onPageChange,
}: HeaderBarProps) {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
@@ -476,7 +474,7 @@ export default function HeaderBar({
>
{t('signIn', language)}
</a>
{!isAdminMode && (
{true && (
<a
href="/register"
className="px-4 py-2 rounded font-semibold text-sm transition-colors hover:opacity-90"
@@ -916,7 +914,7 @@ export default function HeaderBar({
>
{t('signIn', language)}
</a>
{!isAdminMode && (
{true && (
<a
href="/register"
className="block w-full px-4 py-2 rounded font-semibold text-sm text-center transition-colors"

View File

@@ -1,5 +1,4 @@
export interface SystemConfig {
admin_mode: boolean
beta_mode: boolean
}

View File

@@ -24,7 +24,7 @@ import { t } from '../i18n/translations'
export function FAQPage() {
const { language, setLanguage } = useLanguage()
const { user, logout } = useAuth()
const { config: systemConfig } = useSystemConfig()
useSystemConfig() // Load system config but don't use it
return (
<div
@@ -38,8 +38,7 @@ export function FAQPage() {
onLanguageChange={setLanguage}
user={user}
onLogout={logout}
isAdminMode={systemConfig?.admin_mode}
onPageChange={(page) => {
onPageChange={(page) => {
if (page === 'competition') {
window.history.pushState({}, '', '/competition')
window.location.href = '/competition'

View File

@@ -14,11 +14,7 @@ import { useAuth } from '../contexts/AuthContext'
import { useLanguage } from '../contexts/LanguageContext'
import { t } from '../i18n/translations'
export function LandingPage({
isAdminMode = false,
}: {
isAdminMode?: boolean
}) {
export function LandingPage() {
const [showLoginModal, setShowLoginModal] = useState(false)
const { user, logout } = useAuth()
const { language, setLanguage } = useLanguage()
@@ -35,7 +31,6 @@ export function LandingPage({
onLanguageChange={setLanguage}
user={user}
onLogout={logout}
isAdminMode={isAdminMode}
onPageChange={(page) => {
console.log('LandingPage onPageChange called with:', page)
if (page === 'competition') {