async function requiresLoginMiddleware(requiresLoginCheck, req, res, next) {
  if (!req.oidc) {
    next(
      new Error('req.oidc is not found, did you include the auth middleware?')
    );
    return;
  }

  if (requiresLoginCheck(req)) {
    if (!res.oidc.errorOnRequiredAuth && req.accepts('html')) {
      debug(
        'authentication requirements not met with errorOnRequiredAuth() returning false, calling res.oidc.login()'
      );
      return res.oidc.login();
    }
    debug(
      'authentication requirements not met with errorOnRequiredAuth() returning true, calling next() with an Unauthorized error'
    );
    next(
      createError.Unauthorized('Authentication is required for this route.')
    );
    return;
  }

  debug('authentication requirements met, calling next()');

  next();
}
Returns a middleware that checks whether an end-user is authenticated.
If end-user is not authenticated `res.oidc.login()` is triggered for an HTTP
request that can perform a redirect.