fix: replace hardcoded site name with dynamic settings

- Add public /api/settings endpoint (force-dynamic, no auth) exposing
  site_name, site_description, footer_copyright, footer_links
- Navbar, login, register pages fetch site_name via useEffect
- Homepage hero and footer read site_name and site_description from DB
- Fix admin settings form silently ignoring API errors on save
This commit is contained in:
2026-05-19 11:30:05 +02:00
parent 9797519e5c
commit ea5fca6561
6 changed files with 68 additions and 11 deletions
+12 -1
View File
@@ -7,6 +7,7 @@ import { useUser } from '@/context/UserContext'
export function Navbar() {
const [cartCount, setCartCount] = useState(0)
const [siteName, setSiteName] = useState('ShopX')
const { user, refreshUser } = useUser()
const router = useRouter()
@@ -16,6 +17,16 @@ export function Navbar() {
setCartCount(count)
}, [])
useEffect(() => {
fetch('/api/settings')
.then((r) => r.json())
.then((data) => {
const name = data.settings?.site_name
if (name) setSiteName(name as string)
})
.catch(() => {})
}, [])
async function handleLogout() {
await fetch('/api/auth/logout', { method: 'POST' })
await refreshUser()
@@ -28,7 +39,7 @@ export function Navbar() {
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16">
<Link href="/" className="text-xl font-bold text-gray-900">
ShopX
{siteName}
</Link>
<nav className="flex items-center gap-6 text-sm">