| 35 | // Claim the pending code for this session; only the same session can then |
| 36 | // approve or deny it. |
| 37 | const bind = async () => { |
| 38 | const res = await fetch( |
| 39 | `${globalThis.location.origin}/api/auth/device?user_code=${encodeURIComponent(userCode)}`, |
| 40 | { credentials: "include", headers: { accept: "application/json" } }, |
| 41 | ); |
| 42 | if (!alive) return; |
| 43 | if (res.ok) { |
| 44 | setPhase("ready"); |
| 45 | } else { |
| 46 | setPhase("error"); |
| 47 | setError("This device code is unknown, already used, or expired."); |
| 48 | } |
| 49 | }; |
| 50 | void bind(); |
| 51 | return () => { |
| 52 | alive = false; |