DEV Community

phåńtøm šłîçk
phåńtøm šłîçk

Posted on

Nimbus-auth

🌩️ Nimbus Auth: Lightweight Authentication for Node.js

Authentication in Node.js projects can feel heavy. I built Nimbus Auth to make it simple, flexible, and fast — without forcing you into a specific framework or route structure.

🚀 Install

npm install nimbus-auth
Enter fullscreen mode Exit fullscreen mode

⚡ Quick Start

Here’s a minimal server using Express and Nimbus:

import express from "express";
import { signup, login, nimbusMiddleware } from "nimbus-auth";

const app = express();
app.use(express.json());

// Register
app.post("/register", async (req, res) => {
  res.json(await signup(req.body.username, req.body.password));
});

// Sign in
app.post("/signin", async (req, res) => {
  res.json(await login(req.body.username, req.body.password));
});

// Protected route
app.get("/dashboard", nimbusMiddleware, (req, res) => {
  res.json({ message: `Welcome, ${req.user.name}` });
});

app.listen(3000, () => console.log("Nimbus running at http://localhost:3000"));
Enter fullscreen mode Exit fullscreen mode

🖥️ Demo HTML

Drop this into your project to test signup/login quickly:

<!doctype html>
<html>
  <body>
    <h1>Nimbus Demo</h1>
    <input id="username" placeholder="username" />
    <input id="password" type="password" placeholder="password" />
    <button onclick="register()">Register</button>
    <button onclick="signin()">Sign in</button>
    <button onclick="dashboard()">Dashboard</button>
    <pre id="output"></pre>
    <script>
      let token = null;
      async function post(url, body) {
        const res = await fetch(url, {
          method: "POST",
          headers: { "Content-Type": "application/json" },
          body: JSON.stringify(body),
        });
        return res.json();
      }
      async function register() {
        const data = await post("/register", {
          username: username.value,
          password: password.value,
        });
        output.textContent = JSON.stringify(data, null, 2);
      }
      async function signin() {
        const data = await post("/signin", {
          username: username.value,
          password: password.value,
        });
        token = data.token;
        output.textContent = JSON.stringify(data, null, 2);
      }
      async function dashboard() {
        const res = await fetch("/dashboard", {
          headers: { Authorization: "Bearer " + token },
        });
        output.textContent = JSON.stringify(await res.json(), null, 2);
      }
    </script>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

🔑 Why Nimbus?

  • No forced route names — you decide your endpoints.
  • Works with Express and other frameworks.
  • Simple middleware for protecting routes.
  • Lightweight, easy to extend.

📦 Links

🛠️ Roadmap

  • SQLite adapter for persistence
  • Role‑based access control (RBAC)
  • More database adapters (Postgres, MySQL)

Top comments (0)