Node/Express APIs

If your API runs on Node / Express you can use our middleware to secure your endpoints and check that the user is authorized to access them.

Configure Express

Add Kinde Express Middleware as a dependency

The easiest way to install the middleware is via npm:

npm i @kinde-oss/kinde-node-express-api

Integrate with your app

Import the middleware as you would any other Node package - we recommend you do this in you app.js or index.js file depending on your structure.

const kindeAuthExpress = require("@kinde-oss/kinde-node-express-api");

Initialize

In the same file after any other imports initialize the library by entering your Kinde domain. This grabs the verification keys for your app.

let authenticate;
(async () => {
    authenticate = await kindeAuthExpress(YOUR_KINDE_DOMAIN);
})();

Protect!

Any api routes you wish to protect you can now pass the authenticate middleware to. This will verify if the Bearer token sent with the api call matches the keys on your domain and prevent access to unauthorized users.

app.get("/api/me", authenticate);

If a user is not authorized the server will return a 401 Not Authorized response.

Access

If the user was authorized their Kinde id is added to the request object which you can access as follows

app.get("/api/me", authenticate, (req, res) => {
    res.json(req.user);
});

Get more support

Help center

Start here - our help center has everything you need to get started and answer many commonly asked questions.

Visit our help center

Talk to us

If you can’t find what you’re looking for in our help center - email our team. We’d love to hear from you.

Contact support