JS
URL & CREDENTIALS var url = "protected/secret.html", creds = btoa("USER:PASS");
FETCH WITH HTTP AUTH fetch (url, { headers: { "Authorization": `Basic ${creds}` } }) .then((res) => { if (res.status != 200) { throw "Bad Response"; } return res.text(); }) .then((res) => { console.log(res); });
.HTACCESS AuthType Basic AuthName "Password Required" AuthUserFile FOLDER\.htpasswd Require valid-user
RUN HTACCESS IN COMMAND LINE htpasswd -c "PATH/FOLDER/.htpasswd" USER