← back to Sanderson Onboard
scripts/reauth.sh
21 lines
#!/bin/bash
# Headed re-login for the SDG trade portal when the daily cadence flags NEEDS_REAUTH.
# Opens a browser; Steve types the login; cookies persist to chrome-profile so the headless daily job resumes.
export ROOT="$(cd "$(dirname "$0")/.." && pwd)"
node -e '
const puppeteer=require("/Users/macstudio3/Projects/Designer-Wallcoverings/DW-Programming/ImportNewSkufromURL/node_modules/puppeteer");
const ROOT=process.env.ROOT, PROFILE=ROOT+"/chrome-profile", DATA=ROOT+"/data";
const sleep=ms=>new Promise(r=>setTimeout(r,ms));
(async()=>{
const b=await puppeteer.launch({headless:false,defaultViewport:null,userDataDir:PROFILE,args:["--no-sandbox","--start-maximized","--disable-blink-features=AutomationControlled"]});
const p=(await b.pages())[0]||await b.newPage();
await p.goto("https://trade.sandersondesigngroup.com/us/login",{waitUntil:"networkidle2"});
console.log("Log in in the window. Waiting up to 5 min...");
for(let i=0;i<100;i++){ await sleep(3000);
const inz=await p.evaluate(()=>{const t=document.body.innerText.toLowerCase();return t.includes("quick order")||t.includes("my account")||t.includes("sign out");});
if(inz){ require("fs").rmSync(DATA+"/NEEDS_REAUTH",{force:true}); console.log("LOGGED IN — session persisted."); break; }
}
await sleep(2000); await b.close();
})();'
echo "reauth complete (if you logged in). NEEDS_REAUTH cleared if session detected."