fix: client-side auth check instead of middleware rewrite
All checks were successful
Deploy / deploy (push) Successful in 2m38s
All checks were successful
Deploy / deploy (push) Successful in 2m38s
This commit is contained in:
26
app/page.tsx
26
app/page.tsx
@@ -1,7 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect, useCallback, Suspense } from 'react'
|
||||
import { useSearchParams } from 'next/navigation'
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { Thermometer, Droplets, Wind, Calendar, Lock, Settings as SettingsIcon, LogOut, Delete } from 'lucide-react'
|
||||
import Sidebar from '@/components/Sidebar'
|
||||
import TopBar from '@/components/TopBar'
|
||||
@@ -374,9 +373,14 @@ function HomeTab({ weather, sensors }: { weather: WeatherData | null; sensors: S
|
||||
}
|
||||
|
||||
function HomePageInner() {
|
||||
const searchParams = useSearchParams()
|
||||
const isLocked = searchParams.get('locked') === '1'
|
||||
const [unlocked, setUnlocked] = useState(!isLocked)
|
||||
const [unlocked, setUnlocked] = useState<boolean | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/auth')
|
||||
.then(r => r.json())
|
||||
.then(d => setUnlocked(d.authenticated))
|
||||
.catch(() => setUnlocked(false))
|
||||
}, [])
|
||||
|
||||
const [tab, setTab] = useState<Tab>('home')
|
||||
const [activeRoom, setActiveRoom] = useState('living')
|
||||
@@ -431,8 +435,12 @@ function HomePageInner() {
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
if (unlocked === null) {
|
||||
return <div style={{ display: 'flex', height: '100dvh', alignItems: 'center', justifyContent: 'center', background: 'var(--bg)' }}><div className="bg-ambient" /></div>
|
||||
}
|
||||
|
||||
if (!unlocked) {
|
||||
return <LockScreen onUnlock={() => { setUnlocked(true); window.history.replaceState({}, '', '/') }} />
|
||||
return <LockScreen onUnlock={() => setUnlocked(true)} />
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -514,9 +522,5 @@ function HomePageInner() {
|
||||
|
||||
|
||||
export default function HomePage() {
|
||||
return (
|
||||
<Suspense>
|
||||
<HomePageInner />
|
||||
</Suspense>
|
||||
)
|
||||
return <HomePageInner />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user