Files

45 lines
1.3 KiB
JavaScript

const fs = require('fs');
async function getAuth() {
const tokenFile = 'D:/cumin/ghaymah_dns_net_sec_tests/token.json';
if (fs.existsSync(tokenFile)) {
try {
const data = JSON.parse(fs.readFileSync(tokenFile, 'utf8'));
if (data.expiresAt && new Date(data.expiresAt) > new Date(Date.now() + 60000)) {
return data;
}
} catch (e) {}
}
console.log('Requesting new auth token...');
const res = await fetch('https://auth.ghaymah.systems/signin/email-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: 'ziadalex2003@gmail.com', password: '2062003Mz*' })
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Auth failed (${res.status}): ${text}`);
}
const json = await res.json();
const session = json.session;
const tokenData = {
token: session.accessToken,
userId: session.user.id,
expiresAt: new Date(Date.now() + (session.accessTokenExpiresIn || 900) * 1000).toISOString()
};
fs.writeFileSync(tokenFile, JSON.stringify(tokenData, null, 2));
console.log('New token saved successfully!');
return tokenData;
}
module.exports = { getAuth };
if (require.main === module) {
getAuth()
.then(d => console.log('Auth success for user:', d.userId))
.catch(e => console.error('Auth error:', e.message));
}