/** * Re-issue LONG-LIVED (7-day) password-set links to the 3 rescued customers * whose earlier onboarding links were wrongly set to 60 minutes (and have since * expired). None of them set a password yet, so this gets them a working link. * CC justin. Onboarding links should be days, not minutes -- these are paid * customers who just need to get in, not a security reset. * * Run: docker exec performancewest-api-1 node /app/scripts/reissue-onboarding-links.mjs */ import pg from "pg"; import crypto from "crypto"; import nodemailer from "nodemailer"; const CC = "justin@performancewest.net"; const SITE = process.env.DOMAIN ? `https://${process.env.DOMAIN}` : "https://performancewest.net"; const TTL_DAYS = 7; const EMAILS = ["mark@adamslumber.com", "synthetic@pipeline.com", "mitchell@allenscrapmetal.com"]; const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL }); const mailer = nodemailer.createTransport({ host: process.env.SMTP_HOST || "co.carrierone.com", port: parseInt(process.env.SMTP_PORT || "587", 10), secure: false, auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }, }); const FROM = process.env.SMTP_FROM || "Performance West "; for (const email of EMAILS) { const cust = await pool.query(`SELECT id, name, (password_hash IS NOT NULL) AS has_pw FROM customers WHERE lower(email)=lower($1)`, [email]); if (!cust.rows.length) { console.log(`[reissue] no customers row for ${email} - skip`); continue; } const c = cust.rows[0]; if (c.has_pw) { console.log(`[reissue] ${email} already set a password - skip`); continue; } const firstName = (c.name || "there").split(" ")[0]; const token = crypto.randomBytes(32).toString("hex"); await pool.query( `INSERT INTO password_reset_tokens (customer_id, token, expires_at) VALUES ($1,$2,$3)`, [c.id, token, new Date(Date.now() + TTL_DAYS * 24 * 60 * 60 * 1000)], ); const link = `${SITE}/account/reset-password?token=${token}`; await mailer.sendMail({ from: FROM, to: email, cc: CC, subject: "Your Performance West login link (valid 7 days)", html: `

Set your password and log in, ${firstName}

Apologies - the link we sent earlier expired too quickly. Here is a fresh one that stays valid for 7 days.

Set my password →

Or paste this link into your browser:
${link}

Once you're in, you can track your filings and complete any remaining intake. Questions? Reply here or call 1-888-411-0383.

Performance West Inc. · performancewest.net · 1-888-411-0383

`, text: `Hi ${firstName}, apologies the earlier link expired too fast. Set your password to log in (valid 7 days): ${link}. Questions? 1-888-411-0383.`, }); console.log(`[reissue] 7-day login link sent to ${email} (cc ${CC})`); } await pool.end(); console.log("[reissue] DONE");