{"repo":"hormesiel/static-auth","free":true,"listed":false,"github":"https://github.com/hormesiel/static-auth","clone":"git clone https://github.com/hormesiel/static-auth.git","description":"The most simple way to add Basic Authentication to a static website hosted on Vercel.","language":"TypeScript","stars":29,"topics":["basic-authentication","basic-auth","now","authentication","vercel","vercel-now","serverless","static-site","nodejs"],"license":"MIT","category":"auth-billing-email","readme_excerpt":"static-auth The most simple way to add Basic Authentication to a static website hosted on Vercel. I originally created this to add an authentication layer to my projects hosted on Vercel, but it can be used with Node's built-in http module too and should work with Express. Getting started 1. Install the package : 2. Use it : 3. There's no step 3 − it's that easy! (1) Checking credentials via the == or === operators makes your code vulnerable to Timing attacks. This can be solved by using the safe-compare package instead. Examples with Vercel demo source with Node's HTTP module index.js API auth(url, validator, [options]) Required : - url ( String ) : The base url to protect with Basic Authentication. Use / to restrict access to the whole website, or / (e.g. /admin ) to restrict access only to a section of your site. - validator ( Function ) : A function that accepts two parameters ( user and pass ) and returns true if the provided login credentials grant access to the restricted area. Optional : - [options] ( Object ) : - [directory] ( String , defaults to process.cwd() ) : The base path to serve the static assets from. For example, if a request to my-website.com/app.css should return the content of the file located at ./www/app.css (relative to the Node script), then you should set this to dirname + '/www' , otherwise the script will look for ./app.css − which doesn't exist − and return a 404. - [onAuthFailed] ( Function ) : A callback that accepts one parameter ( res , an h","default_branch":null,"files":null,"tree":[],"storefront":"/r/hormesiel","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/hormesiel/static-auth/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}