- Add show_scans_public and show_guides_public columns to projects table - Add visibility toggles to editor sidebar settings panel (auto-save) - Add visibility toggles to project settings dialog (auto-save) - Propagate settings to community viewer (hide scans/guides for non-owners) - Add updateProjectVisibility server action - Fix username onboarding dialog stuck after DB reset (validate update affected rows) - Add error handling to UsernameGate for stale sessions Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { useAuth } from '../lib/auth/hooks'
|
|
import { getUsername } from '../lib/auth/actions'
|
|
import { UsernameOnboardingDialog } from './username-onboarding-dialog'
|
|
|
|
export function UsernameGate({ children }: { children: React.ReactNode }) {
|
|
const { isAuthenticated, isLoading } = useAuth()
|
|
const [needsUsername, setNeedsUsername] = useState(false)
|
|
const [checking, setChecking] = useState(true)
|
|
|
|
useEffect(() => {
|
|
if (isLoading) return
|
|
if (!isAuthenticated) {
|
|
setChecking(false)
|
|
setNeedsUsername(false)
|
|
return
|
|
}
|
|
getUsername()
|
|
.then((username) => {
|
|
setNeedsUsername(!username)
|
|
setChecking(false)
|
|
})
|
|
.catch(() => {
|
|
setNeedsUsername(false)
|
|
setChecking(false)
|
|
})
|
|
}, [isAuthenticated, isLoading])
|
|
|
|
return (
|
|
<>
|
|
{children}
|
|
<UsernameOnboardingDialog
|
|
open={needsUsername && !checking}
|
|
onComplete={() => setNeedsUsername(false)}
|
|
/>
|
|
</>
|
|
)
|
|
}
|