'use client' import { useState } from 'react' import { cn, Input, Label } from '@sim/emcn' import { getErrorMessage } from '@sim/utils/errors' import { Eye, EyeOff } from 'lucide-react' import { useRouter } from 'next/navigation' import { AuthSubmitButton } from '@/app/(auth)/components' import { PublicFileAuthShell } from '@/app/f/[token]/public-file-auth-shell' import { usePublicFileAuth } from '@/hooks/queries/public-shares' interface PublicFileAuthProps { token: string } /** * Password gate for a protected public file share. On success the * `file_auth_{shareId}` cookie is set and the page re-renders the viewer. */ export function PublicFileAuth({ token }: PublicFileAuthProps) { const router = useRouter() const authenticate = usePublicFileAuth(token) const [password, setPassword] = useState('') const [showPassword, setShowPassword] = useState(false) const [error, setError] = useState(null) const handleAuthenticate = async () => { if (!password.trim()) { setError('Password is required.') return } setError(null) try { await authenticate.mutateAsync({ password }) router.refresh() } catch (err) { setError(getErrorMessage(err, 'Invalid password. Please try again.')) } } return (
{ e.preventDefault() handleAuthenticate() }} className='space-y-6' >
{ setPassword(e.target.value) setError(null) }} className={cn( 'pr-10', error && 'border-[var(--text-error)] focus:border-[var(--text-error)]' )} />
{error ?

{error}

: null}
Continue
) }