Monorepo for Aesthetic.Computer aesthetic.computer
at main 88 lines 2.9 kB view raw
1#!/usr/bin/env node 2// Query Auth0 for recent user signups with created_at timestamps 3 4import { shell } from '/workspaces/aesthetic-computer/system/backend/shell.mjs'; 5import { config } from 'dotenv'; 6 7config(); 8 9async function getAuth0RecentUsers(tenant = 'aesthetic') { 10 try { 11 const { got } = await import('got'); 12 13 const clientId = tenant === 'aesthetic' 14 ? process.env.AUTH0_M2M_CLIENTID 15 : process.env.SOTCE_AUTH0_M2M_CLIENTID; 16 const clientSecret = tenant === 'aesthetic' 17 ? process.env.AUTH0_M2M_CLIENT_SECRET 18 : process.env.SOTCE_AUTH0_M2M_CLIENT_SECRET; 19 const baseURI = tenant === 'aesthetic' 20 ? 'https://aesthetic.us.auth0.com' 21 : 'https://sotce.us.auth0.com'; 22 23 // Get access token 24 const tokenResponse = await got.post(`${baseURI}/oauth/token`, { 25 json: { 26 client_id: clientId, 27 client_secret: clientSecret, 28 audience: `${baseURI}/api/v2/`, 29 grant_type: 'client_credentials', 30 }, 31 responseType: 'json', 32 }); 33 34 const token = tokenResponse.body.access_token; 35 36 // Query users sorted by created_at descending 37 const response = await got(`${baseURI}/api/v2/users`, { 38 searchParams: { 39 sort: 'created_at:-1', // Most recent first 40 per_page: 20, 41 page: 0, 42 fields: 'user_id,email,created_at', 43 include_fields: true, 44 }, 45 headers: { Authorization: `Bearer ${token}` }, 46 responseType: 'json', 47 }); 48 49 return response.body; 50 } catch (error) { 51 shell.error(`Error querying Auth0: ${error.message}`); 52 return null; 53 } 54} 55 56console.log('\n🔍 Querying Auth0 for recent user signups...\n'); 57 58// Query both tenants 59const aestheticUsers = await getAuth0RecentUsers('aesthetic'); 60const sotceUsers = await getAuth0RecentUsers('sotce'); 61 62if (aestheticUsers) { 63 console.log('📅 Recent AESTHETIC tenant signups:\n'); 64 aestheticUsers.forEach((user, i) => { 65 const createdAt = new Date(user.created_at); 66 const hoursAgo = (Date.now() - createdAt.getTime()) / (1000 * 60 * 60); 67 console.log(`${i + 1}. ${user.user_id}`); 68 console.log(` Email: ${user.email || 'N/A'}`); 69 console.log(` Created: ${createdAt.toISOString()}`); 70 console.log(` ${hoursAgo.toFixed(1)} hours ago (${(hoursAgo / 24).toFixed(1)} days)`); 71 console.log(''); 72 }); 73} 74 75if (sotceUsers) { 76 console.log('\n📅 Recent SOTCE tenant signups:\n'); 77 sotceUsers.forEach((user, i) => { 78 const createdAt = new Date(user.created_at); 79 const hoursAgo = (Date.now() - createdAt.getTime()) / (1000 * 60 * 60); 80 console.log(`${i + 1}. ${user.user_id}`); 81 console.log(` Email: ${user.email || 'N/A'}`); 82 console.log(` Created: ${createdAt.toISOString()}`); 83 console.log(` ${hoursAgo.toFixed(1)} hours ago (${(hoursAgo / 24).toFixed(1)} days)`); 84 console.log(''); 85 }); 86} 87 88console.log('\n⏰ Current time:', new Date().toISOString());