Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

keeps: hoist initAuth0 + token refresh before connectWallet

The prior guard sat after connectWallet, which was too late:
connectWallet -> syncWalletToProfile early-returns when acToken is null,
so on first modal open the wallet never got written to the user's profile
in MongoDB. keep-prepare then rejected with "No wallet linked" (new mint)
or skipped wallet-based ownership shortcuts. On second open acToken was
already populated from the first attempt's getTokenSilently, so the sync
ran and validate passed — which matches the reported "close & reopen fixes
it" symptom.

Hoisting the guard to the top of startMintFlow ensures syncWalletToProfile
has a token on the first open too.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

+12 -11
+12 -11
system/public/kidlisp.com/keeps.html
··· 6026 6026 mintAbortController = new AbortController(); 6027 6027 6028 6028 try { 6029 + // Ensure Auth0 + acToken are ready BEFORE connectWallet runs, because 6030 + // connectWallet → syncWalletToProfile early-returns if acToken is null, 6031 + // leaving the user's profile without the linked wallet. keep-prepare 6032 + // then rejects with "No wallet linked" on first open; second open 6033 + // works because the first getTokenSilently populated acToken. 6034 + if (!acAuth0Client) { 6035 + try { await initAuth0(); } catch {} 6036 + } 6037 + if (acAuth0Client) { 6038 + try { acToken = await acAuth0Client.getTokenSilently(); } catch {} 6039 + } 6040 + 6029 6041 // Step 1: Connect wallet 6030 6042 addTrackEntry(rebake ? 'Starting regeneration...' : (regenerate ? 'Starting regeneration...' : 'Starting keep flow...'), 'active'); 6031 6043 setMintStep('wallet', 'active', 'Connecting...'); ··· 6037 6049 } 6038 6050 setMintStep('wallet', 'done', address.slice(0, 8) + '...' + address.slice(-4)); 6039 6051 addTrackEntry('Wallet connected: ' + address.slice(0, 8) + '...' + address.slice(-4)); 6040 - 6041 - // Refresh token — ensure Auth0 has finished initializing before we 6042 - // decide whether to send the Authorization header. Without this guard, 6043 - // a fast first click can race initAuth0() and POST keep-prepare without 6044 - // auth, producing a spurious 401 "Please log in first" on first open. 6045 - if (!acAuth0Client) { 6046 - try { await initAuth0(); } catch {} 6047 - } 6048 - if (acAuth0Client) { 6049 - try { acToken = await acAuth0Client.getTokenSilently(); } catch {} 6050 - } 6051 6052 6052 6053 // Step 2: Create job via keep-prepare 6053 6054 setMintStep('validate', 'active', rebake ? 'Validating ownership...' : (regenerate ? 'Regenerating...' : 'Validating...'));