Registry / auth-security / stage-auth-middleware

stage-auth-middleware

JSON →
library1.0.9jsnpmunverified

The `stage-auth-middleware` package provides an Express.js middleware specifically designed to secure staging environments for Akarion-related websites. Its core function is to enforce user authentication for access to stage URLs, thereby restricting public access, and to display a visual hint on the page indicating that the user is currently interacting with a staging site. The package is currently stable at version 1.0.9. It operates with an irregular release cadence, likely aligned with internal development cycles rather than public feature rollouts. This utility is highly specialized, serving a niche within the Akarion ecosystem, and should not be considered a general-purpose authentication solution. Its primary differentiator is its tailored integration with specific staging security requirements, offering a streamlined approach without the overhead of more comprehensive identity management systems.

npm install stage-auth-middleware
INSTALL
IMPORT
SIG · STAGE-AUTH-MIDDLEW
S
stage-auth-middleware
auth-securityjavascriptv1.0.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

stageAuthMiddleware
import stageAuthMiddleware from 'stage-auth-middleware';
const stageAuthMiddleware = require('stage-auth-middleware');
While the README shows CommonJS `require`, it exports as a default module, so ESM `import` is the idiomatic way. Both work.
stageAuthMiddleware (CJS)
const stageAuthMiddleware = require('stage-auth-middleware');
This is the CommonJS pattern shown in the original documentation and is fully supported in Node.js environments.
Middleware Configuration
app.use(stageAuthMiddleware({ pass: process.env.STAGE_AUTH_PASS || 'default-password', enabled: process.env.NODE_ENV !== 'production' }));
app.use(stageAuthMiddleware);
The middleware must be called as a function with an options object, including a 'pass' and 'enabled' property, to be correctly initialized.

This quickstart initializes an Express server with the stage-auth-middleware, demonstrating basic setup and environment variable usage for the password, and a simple route.

import express from 'express'; import stageAuthMiddleware from 'stage-auth-middleware'; const app = express(); // It's crucial to load environment variables first in a real app (e.g., using dotenv) const STAGE_AUTH_PASS = process.env.STAGE_AUTH_PASS || 'your-secret-staging-pass'; app.use(stageAuthMiddleware({ pass: STAGE_AUTH_PASS, enabled: process.env.NODE_ENV !== 'production' // Only enable for non-production environments })); // Example route app.get('/', (req, res) => { res.send('<h1>Welcome to the Staging Site!</h1><p>You have authenticated successfully.</p>'); }); // IMPORTANT: Ensure the client-side script is served. // If you are not serving static files from the root, you might need a dedicated route: // app.get('/stage-auth-middleware.js', (req, res) => { // res.sendFile(path.resolve('node_modules/stage-auth-middleware/dist/client.js')); // (path might vary) // // This library might also serve it implicitly based on configuration. // }); const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`Staging server running on http://localhost:${PORT}`); console.log('Access with password: ' + STAGE_AUTH_PASS); });
Debug
Known issues
gotchaThe `pass` option should never be hardcoded or exposed in production environments. Always use environment variables (e.g., `process.env.STAGE_AUTH_PASS`) to manage this password securely, especially in non-production deployments.
fix
Replace hardcoded `pass` strings with `process.env.YOUR_SECRET_VAR` and ensure this variable is set in your deployment environment.
affects: >=1.0.0
gotchaThis middleware is specifically designed for 'Akarion' staging sites and internal use. While it might function elsewhere, its features and underlying assumptions may not align with general-purpose authentication needs or other project ecosystems. Using it outside its intended context may lead to unexpected behavior or security gaps.
fix
Evaluate if this specific middleware truly fits your use case if you are not operating within the Akarion staging environment; consider a more generic authentication solution if not.
affects: >=1.0.0
gotchaFor the staging hint and client-side authentication flow to work correctly, the `<script src="/stage-auth-middleware.js"></script>` tag *must* be included in the HTML files of your staging application. If this script is not loaded, users may experience an incomplete or non-functional authentication process and will not see the staging indicator.
fix
Ensure the client-side script `<script src="/stage-auth-middleware.js" async defer></script>` is present in the `<head>` or `<body>` of all HTML pages that require staging authentication. Confirm your Express server configuration serves this static file correctly, typically by mounting a static middleware.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: app.use() requires middleware functions but got a Object
The `stageAuthMiddleware` function was not called with its configuration object when passed to `app.use()`. It expects `stageAuthMiddleware({ options })`.
fix
Ensure you call the middleware function with an options object: `app.use(stageAuthMiddleware({ pass: 'your-pass', enabled: true }))`.
ReferenceError: require is not defined in ES module scope
You are attempting to use CommonJS `require` syntax in an ES module (`type: "module"` in `package.json` or `.mjs` file).
fix
Change your import statement to `import stageAuthMiddleware from 'stage-auth-middleware';`.
Error: Missing 'pass' option for stage-auth-middleware
The `pass` option is a mandatory configuration parameter for the middleware, and it was not provided or was `undefined`.
fix
Ensure the `pass` property is present and has a string value in the options object passed to the middleware, e.g., `stageAuthMiddleware({ pass: process.env.YOUR_SECRET, enabled: true })`.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies
expressrequiredThis package is an Express.js middleware and requires an Express application to function.
Agent activity
15 hits · last 30 days
node
10
OpenAI (training)
1
Resources
stage-auth-middleware — npm install stage-auth-middleware · libregistry