+ {/* What the window ends on, so the error page is expected rather than alarming. */}
+
+
+
+ 127.0.0.1:1455/auth/callback?code=…
+
+
{
+ if (pasted.trim() || busy) return;
+ if (!navigator.clipboard?.readText || !window.isSecureContext) {
+ inputRef.current?.focus();
+ return;
+ }
+ navigator.clipboard.readText().then(
+ (text) => {
+ if (!paste(text)) inputRef.current?.focus();
+ },
+ () => inputRef.current?.focus()
+ );
+ });
useEffect(() => {
if (!opened) return;
- const onVisible = () => {
- if (document.visibilityState === 'visible') inputRef.current?.focus();
+ const onBack = () => {
+ if (document.visibilityState === 'visible') takeCopied();
+ };
+ document.addEventListener('visibilitychange', onBack);
+ window.addEventListener('focus', onBack);
+ return () => {
+ document.removeEventListener('visibilitychange', onBack);
+ window.removeEventListener('focus', onBack);
};
- document.addEventListener('visibilitychange', onVisible);
- return () => document.removeEventListener('visibilitychange', onVisible);
}, [opened]);
/** A fresh sign-in: the old one ran out or was used up. */
diff --git a/server/tests/helpers/factories/tokens.ts b/server/tests/helpers/factories/tokens.ts
index 670905571..b48f3c228 100644
--- a/server/tests/helpers/factories/tokens.ts
+++ b/server/tests/helpers/factories/tokens.ts
@@ -20,13 +20,17 @@ export async function makeMcpToken(
): Promise<{ token: EntityDTO; rawToken: string }> {
const { rawToken: given, ...columns } = overrides;
const rawToken = given ?? `trek_test_${nextSeq('mcp-token')}_${randomBytes(8).toString('hex')}`;
- const token = await createRow(orm, McpTokens, {
- user: userId,
- name: 'Test Token',
- token_hash: sha256(rawToken),
- token_prefix: rawToken.slice(0, 12),
- ...columns,
- });
+ const token = await createRow(
+ orm,
+ McpTokens,
+ {
+ user: userId,
+ name: 'Test Token',
+ token_hash: sha256(rawToken),
+ token_prefix: rawToken.slice(0, 12),
+ },
+ columns,
+ );
return { token, rawToken };
}
@@ -44,16 +48,20 @@ export async function makeOauthClient(
const n = nextSeq('oauth-client');
const secret = given ?? `test-secret-${n}-${randomBytes(8).toString('hex')}`;
const id = givenId ?? `test-oauth-client-${n}`;
- await insertRow(orm, OauthClients, {
- id,
- user: userId,
- name: `Test Client ${n}`,
- client_id: `client-${n}`,
- client_secret_hash: sha256(secret),
- redirect_uris: JSON.stringify(['https://client.example.test/callback']),
- allowed_scopes: JSON.stringify(['trips:read']),
- ...columns,
- });
+ await insertRow(
+ orm,
+ OauthClients,
+ {
+ id,
+ user: userId,
+ name: `Test Client ${n}`,
+ client_id: `client-${n}`,
+ client_secret_hash: sha256(secret),
+ redirect_uris: JSON.stringify(['https://client.example.test/callback']),
+ allowed_scopes: JSON.stringify(['trips:read']),
+ },
+ columns,
+ );
const client = await findRow(orm, OauthClients, { id });
if (!client) throw new Error(`makeOauthClient: no client ${id} after its insert`);
return { client, secret };