middleware

Contains all middleware for expressjs endpoints.
Source:

Methods

secured()

Source:
Middleware to authenticate JWT from the spool spa that are generated by Auth0.
Example
router.get('/', secured, (req, res, next) => {
 res.send("This user is authorized to access this API endpoint");
});

(inner) authorized(req, res, next)

Source:
Middleware to authorize devices that have completed mutual TLS authentication.
Example
router.post('/', authorized, (req, res, next) => {
 res.send("Device authenticated successfully!")
});
Parameters:
Name Type Description
req Object an expressjs request object.
res Object an expressjs response object.
next function the expressjs next function.

(inner) databaseWrap(fn)

Source:
Middleware to wrap request to the database and provide automatic error response handling.
Parameters:
Name Type Description
fn function The function to wrap.

(inner) userInApi()

Source:
See:
  • secured
Middleware to provide the user in api endpoints that are protected with secured().

(inner) wrapAsync(fn) → {function}

Source:
Wraps async expressjs endpoint functions so that they resolve and have errors caught properly.
Example
router.get('/', wrapAsync(async (req, res, next) => {
 const responseData = await someAsyncFunction();
 res.send(responseData);
 }));
Parameters:
Name Type Description
fn function An async function to wrap that accepts (req, res, next) or (req, res) as parameters.
Returns:
A function that wraps fn, forcing it to resolve and catching any errors.
Type
function