import { useEffect, useState } from 'react' import { call, useAction, where } from './api' /** * The page RecFlare Studio opens after `POST /connect/deviceauthorization`. * * Studio shows `verification_uri` (`/device`) and opens `verification_uri_complete` * (`/device?user_code=…`) in the browser. The API that created the code stays on * `auth`; this page only approves or denies it, with the website session's token. */ export function DeviceLinkPage({ account, search, navigate, }: { /** undefined while the session is still being checked, null when signed out. */ account: { username: string } | null | undefined search: string navigate: (to: string) => void }) { const fromQuery = new URLSearchParams(search).get('user_code') ?? '' const [code, setCode] = useState(fromQuery) const { pending, error, done, run } = useAction() useEffect(() => { if (account !== null) return const next = `/device${search}` navigate(`/login?next=${encodeURIComponent(next)}`) }, [account, navigate, search]) if (!account) { return (

{account === undefined ? 'Loading…' : 'Redirecting to sign in…'}

) } const submit = (path: 'approve' | 'deny') => { void run(async () => { await call(`${where().auth}/connect/device/${path}`, { authed: true, form: { user_code: code.trim() }, }) return path === 'approve' ? 'Studio is signed in. You can close this tab and go back to the editor.' : 'Studio was not signed in. You can close this tab.' }) } return (

Sign in to RecFlare Studio

The editor asked to use {account.username}. The code below is the one Studio is showing. Allowing it signs the editor into this account.

{ e.preventDefault() submit('approve') }} >
{error &&

{error}

} {done &&

{done}

}
) }