Stage Auth Middleware

1.0.9 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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);
});

view raw JSON →