import { useState } from 'react' import { useOpenCodeServerAuth } from '@/hooks/useOpenCodeServerAuth' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Alert, AlertDescription } from '@/components/ui/alert' import { CheckCircle2, Eye, EyeOff } from 'lucide-react' import { SettingsDisclosure } from './SettingsDisclosure' interface OpenCodeServerAuthSettingsProps { isOpen?: boolean onToggle?: () => void } export function OpenCodeServerAuthSettings({ isOpen: controlledOpen, onToggle }: OpenCodeServerAuthSettingsProps = {}) { const { status, setPassword, clearPassword } = useOpenCodeServerAuth() const [password, setPasswordValue] = useState('') const [showPassword, setShowPassword] = useState(false) const [uncontrolledOpen, setUncontrolledOpen] = useState(true) const isOpen = controlledOpen ?? uncontrolledOpen const handleToggle = onToggle ?? (() => setUncontrolledOpen((open) => !open)) const handleSave = () => { if (password.length >= 8) { setPassword.mutate(password) setPasswordValue('') setShowPassword(false) } } const getStatusText = () => { if (!status) return 'Loading...' if (status.source === 'db') return 'Set (configured via UI)' if (status.source === 'env') return 'Set (configured via env var)' return 'Auto-generated by OpenCode Manager' } const getStatusIcon = () => { if (!status) return null if (status.source === 'db') return if (status.source === 'env') return return } return ( {getStatusIcon()} {getStatusText()} } > {status?.source === 'managed' && ( OpenCode Manager generates and stores this password automatically. Set your own below to override it. )} setPasswordValue(e.target.value)} placeholder="Enter new password" className="pr-9" autoComplete="new-password" name="opencode-server-password" /> setShowPassword(!showPassword)} className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground" > {showPassword ? : } {setPassword.isPending ? 'Saving...' : 'Save'} {password.length > 0 && password.length < 8 && ( Password must be at least 8 characters )} {status?.source === 'db' && ( clearPassword.mutate()} disabled={clearPassword.isPending} > {clearPassword.isPending ? 'Clearing...' : 'Use auto-generated password'} )} ) }
Password must be at least 8 characters