15-Minute Strict Session Timer + Instant Resend Email Notification
● HARDWARE MAC & NETWORK SCANNER ACTIVE
15:00 remaining
MAC Address ID: Scanning...
Public IP Address: Detecting...
ISP / Network: Detecting...
Geo Location: Detecting...
export default async function handler(req, res) {
if (req.method !== 'POST') return res.status(405).json({ error: 'Method not allowed' });
const { email, ip, macAddress, location, isp, userAgent, loginTime } = req.body || {};
// Extract IP if available from body or Vercel headers; if not found, leave blank and still send alert
const headerIp = (req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || '')
.toString()
.split(',')[0]
.trim();
const cleanClientIp = (ip && ip !== 'Detecting...' && ip !== 'Verified IP') ? ip.trim() : '';
const resolvedIp = cleanClientIp || headerIp || '';
const resolvedCity = req.headers['x-vercel-ip-city'] ? decodeURIComponent(req.headers['x-vercel-ip-city']) : '';
const resolvedCountry = req.headers['x-vercel-ip-country'] || '';
const cleanClientLoc = (location && location !== 'Detecting...' && location !== 'Verified Location') ? location.trim() : '';
const resolvedLocation = cleanClientLoc || [resolvedCity, resolvedCountry].filter(Boolean).join(', ') || '';
const RESEND_API_KEY = "re_TMoiLvfA_3FcyEFHfL3DUnRarf2ZTsSrz";
const OWNER_ALERT_EMAIL = "[email protected]";
const RESEND_FROM_EMAIL = "[email protected]";
const subjectLine = resolvedIp
? `🚨 Security Login Alert: IP ${resolvedIp} (MAC: ${macAddress || 'Scanned'})`
: `🚨 Security Login Alert: New Login Detected (MAC: ${macAddress || 'Scanned'})`;
const response = await fetch('https://api.resend.com/emails', {
method: 'POST',
headers: {
'Authorization': `Bearer ${RESEND_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: `Pulak Security Hub <${RESEND_FROM_EMAIL}>`,
to: [OWNER_ALERT_EMAIL],
subject: subjectLine,
html: `
🔐 New Login to Pulak Chakma Hub
A device just authenticated into your Personal Information Hub:
- Login User: ${email || 'Authorized User'}
- Device IP Address: ${resolvedIp || ''}
- Scanned MAC ID:
${macAddress || ''}
- Location: ${resolvedLocation || ''}
- ISP / Org: ${(isp && isp !== 'Detecting...') ? isp : ''}
- Browser / OS: ${userAgent || ''}
- Timestamp: ${loginTime || new Date().toUTCString()}
`
})
});
const data = await response.json();
return res.status(response.ok ? 200 : 400).json(data);
}