'use client'; import {useEffect,useState} from 'react'; import {ArrowUpRight,Music2} from 'lucide-react'; import {startSignIn} from '@/lib/sign-in'; import {useSession} from '@/components/shell/session'; /** `next` is the page sign-in returns to; it defaults to this one. */ type Copy={title?:React.ReactNode;blurb?:string;next?:string}; export default function SignIn({title=<>Your music.
Written down.,blurb='Turn your audio recordings into a score you can play, edit, and make your own.',next}:Copy={}){ const [retry,setRetry]=useState(false),[embedded,setEmbedded]=useState(true),[waiting,setWaiting]=useState(false),[login,setLogin]=useState('/auth/login'); const [blocked,setBlocked]=useState(false),{refresh}=useSession(); // A browser that blocks third-party cookies keeps the popup's session from this // embedded page until the page is given storage access. useEffect(()=>{if(window.self!==window.top)document.hasStorageAccess?.().then(has=>setBlocked(!has),()=>{});},[]); async function allowAccess(){ try{await document.requestStorageAccess();setBlocked(false);}catch{} refresh(); } // Come back to the page sign-in started from; the server only honours known pages. useEffect(()=>{setRetry(new URLSearchParams(location.search).get('signIn')==='retry');setEmbedded(window.self!==window.top); const back=next??location.pathname;setLogin(back!=='/'?'/auth/login?next='+encodeURIComponent(back):'/auth/login');},[next]); useEffect(()=>{ if(typeof BroadcastChannel==='undefined')return; const channel=new BroadcastChannel('kiku-auth'); channel.onmessage=event=>{if(event.data!=='signed-in')setWaiting(false);}; return()=>channel.close(); },[]); function signIn(event:React.MouseEvent){ event.preventDefault(); setWaiting(startSignIn(next)); } return

{title}

{blurb}

Sign in with Hugging Face

Use your account’s free processing allowance.
New here? You can create an account when you sign in.

{embedded&&

{waiting ?'Finish signing in through the pop-up window. This page updates by itself.' :'Hugging Face opens sign-in in a small window, then brings you straight back here.'}

} {embedded&&blocked&&waiting&&

Signed in, but this page still asks? Your browser keeps embedded pages apart. or{' '} open Kiku AI in its own tab.

} {retry&&

Sign-in didn’t complete. Please try again.

}
; }