Node/Express APIs

These instructions assume you already have a Kinde account. You can register for free here (no credit card required).

This guide details how to protect your GraphQL endpoints, when running on ExpressJS.

It assumes you already have a frontend connected to Kinde which is sending a Kinde issued bearer token to your API for verification.

If you don’t yet have a frontend setup, please set this up first following the relevant guide:

React

NextJS

VanillaJS

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

Environments

If you would like to use our Environments feature as part of your development process. You will need to create them first within your Kinde account, see the guide here. In this case you would use the Environment subdomain in the code block above.

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

If you need any assistance with getting Kinde connected reach out to us at support@kinde.com.

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
Talk to us