0.4.0 • Published 3 years ago

@qloud/express v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Qloud Integration for Express

Express middleware to use Qloud for authentication.

Install the dependency:

npm install --save @qloud/express

Add the Qloud middleware to your Express application:

const qloud = require("@qloud/express");

app.use(qloud({secret: "insert-qloud-secret-here"}));

If the user is authenticated, the data from the JWT token will be available in the auth property of the request:

app.get("/", (req, res) => {
    res.json(req.auth);
});

Requests with an invalid or expired token will be redirected to the login page. If a request does not contain a token, req.auth is undefined. You can enable the configuration option credentialsRequired if you also want to redirect requests without a token to the login page:

app.use(qloud({secret: "insert-qloud-secret-here", credentialsRequired: true}));

This option is set to false by default to support applications with optional authentication (see authentication modes).

Minimal Example

const express = require("express");
const qloud = require("@qloud/express");

const port = process.env.PORT || 3000;
const app = express();
app.use(qloud({secret: "insert-qloud-secret-here"}));

app.get("/", (req, res) => {
    res.json(req.auth);
});

app.listen(port);