Basic Authentication for Vantage.js
vantage-auth-basic is an authentication extension designed for the vantage.js interactive CLI framework. It provides basic authentication capabilities, prompting users for usernames and passwords configured on the Vantage server. Key features include configurable retry limits for incorrect password attempts, a delay between retries, and an account lockout mechanism with a specified unlock timeout. As of version 1.0.0, this extension is tightly integrated with vantage.js and is often used by simply specifying the string "basic" in the vantage.auth() method, negating the need for a separate `require()` call when used within a Vantage application. Given the vantage.js framework's last significant activity being several years ago, this package is effectively abandoned and not recommended for new projects.
Common errors
-
Access denied: too many login attempts.
cause The user failed to authenticate within the configured 'retry' limit, leading to a session kick-out.fixCheck the username and password for correctness. If locked out, wait for the 'unlockTime' duration to expire, or restart the Vantage session if the lockout is session-bound. Review the 'retry' and 'unlockTime' options in your configuration for appropriate values.
Warnings
- breaking This package and its parent framework, Vantage.js, are no longer actively maintained. Using them in modern Node.js environments (v12+) may lead to compatibility issues, unpatched security vulnerabilities, or unexpected behavior. It is strongly advised not to use this package for new projects or in production environments.
- gotcha This package is part of the older Vantage.js ecosystem, primarily designed for CommonJS environments and Node.js versions up to 0.x / 1.x. Modern Node.js projects (ESM-first, recent Node versions) will encounter compatibility issues with `require()` and may prefer more modern authentication solutions.
- gotcha Direct `require("vantage-auth-basic")` is often unnecessary. Vantage.js itself integrates this authentication method, allowing users to simply pass the string "basic" to `vantage.auth()`. Relying on the string is generally preferred for consistency with the framework.
- gotcha User passwords are configured directly in memory via the `users` option. For production environments, consider implementing a more secure password storage and verification mechanism (e.g., hashing passwords and verifying against a database) rather than hardcoded credentials. This package does not provide robust password management or hashing itself.
Install
-
npm install vantage-auth-basic -
yarn add vantage-auth-basic -
pnpm add vantage-auth-basic
Imports
- basicAuth
import basicAuth from 'vantage-auth-basic';
var basicAuth = require("vantage-auth-basic"); - "basic" string identifier
vantage.auth("basic", options);
Quickstart
var users = [
{ user: "admin", pass: "4k#842jx!%s" },
{ user: "user", pass: "Unicorn11" }
];
var vantage = require("vantage")();
vantage.auth("basic", {
"users": users,
"retry": 3,
"retryTime": 500,
"deny": 1,
"unlockTime": 3000
});
vantage
.command("whoami", "Outputs logged in user.")
.action(function(args, cb){
console.log("You are " + this.user);
cb();
});
// To make the Vantage instance active, you would typically call .listen() or similar.
// For example, vantage.listen(4000) or run it from the command line if installed globally.
// This snippet primarily demonstrates the authentication setup.