// e2e/decode_token.js const fs = require('fs'); const path = require('path'); const file = '/tmp/token_resp.txt'; if (!fs.existsSync(file)) { console.error('token response file not found:', file); process.exit(2); } const s = fs.readFileSync(file, 'utf8'); const m = s.match(/"token":"([^"]+)"/); if (!m) { console.error('token not found in file'); process.exit(2); } const t = m[1]; console.log('TOKEN:', t); const parts = t.split('.'); if (parts.length < 2) { console.error('invalid token'); process.exit(2); } let payload = parts[1]; payload += '='.repeat((4 - (payload.length % 4)) % 4); try { const buf = Buffer.from(payload.replace(/-/g,'+').replace(/_/g,'/'), 'base64'); const json = buf.toString('utf8'); try { const obj = JSON.parse(json); console.log('PAYLOAD:'); console.log(JSON.stringify(obj, null, 2)); } catch (e) { console.log('decoded payload (not json):', json); } } catch (err) { console.error('decode error', err); process.exit(1); }