Skip to content
A very-basic-express-auth-example Example using the challenge Auth and NeDB
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
db
public
.env
.gitignore
README.md
config.js
package-lock.json
package.json
server.js

README.md

A very-basic-express-auth-example Example

This is an example of setting up a basic "challenge auth" with express-basic-auth

Demos

With NeDB

To see this example using NeDB, check out this link

With Mongodb

To see this example using mongodb, check out this link

header image

The key features to note are:

config.js

this is where your server.js will grab the USERNAME and PASSWORD to approve or deny use of your application.

The USERNAME and PASSWORD will be defined either using the .env file:

USERNAME=joey
PASSWORD=super_secret_password

OR by doing the following:

USERNAME=joey PASSWORD=super_secret_password npm start

server.js

You can find the usual express routes and api endpoints, except now we add the challengeAuth middleware at each of our routes. What this does is that before any of requests -- GET, POST in this case -- the server checks to see if the client has authenticated or not. If the client has not authenticated, then a menu will appear to add in a basic username and password authentication. The username and password are defined in the step above.

You can’t perform that action at this time.