feat(service): add wait_for_approval and return the cache for a login with no prompt

A pair code shown in a log line never answers a prompt, so the server read that login as anonymous and kept the session cache.
This commit is contained in:
imSp4rky
2026-10-07 09:03:18 -06:00
parent 3fd69e8039
commit 5b0369e63a
12 changed files with 97 additions and 36 deletions
+18
View File
@@ -256,6 +256,24 @@ REST download job shows it as `input_prompt`. Locally it routes through the
shared Rich console (`prompt_user`) so the prompt renders correctly alongside
progress and log output.
For a login that the user approves on another device (a pair code, a QR code),
use `self.wait_for_approval(message, check, timeout)`, never a hand-written
loop. It shows the message, then calls `check` at each interval until `check`
returns a value. `check` returns `None` while the approval is pending.
```python
token = self.wait_for_approval(
f"Open {self.config['endpoints']['pair']} and enter code {code}",
check=lambda: self.poll_pair_token(code),
timeout=expires_in,
)
```
It raises `TimeoutError` after `timeout` seconds. Under `serve` mode it also stops
when the client deletes the remote session, so the loop does not continue on the
server with no client. The message goes out as a log line, so a remote
session shows it, but a REST download job does not relay it as `input_prompt`.
!!! warning "Make each token cache entry unique"
The cache above uses `tokens_{device}_{profile}` on purpose. A token cache
must include every dimension that changes the token (device, profile, or