React SDK
SDKs and 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 Node.js.
It assumes you already have a front end connected to Kinde which is sending a Kinde issued bearer token to your API for verification.
If you don’t yet have a front end setup, please set this up first following the relevant guide:
You can use our Node.js SDK to secure your endpoints and check that the user is authorized to access them.
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.
Import the library as you would any other Node package - we recommend you do this in you app.js
or index.js
file depending on your structure.
In the same file after any other imports initialize the library by entering your Kinde domain. This grabs the verification keys for your app.
The Apollo docs provide a few ways for securing your APIs. We will use the approach of adding the user object to the context.
It’s pretty common that a Graph will have a mix of public and private fields.
Because we’ve added the user to context we can access this in the individual field resolvers and decide what to return.
As an example, this resolver is only accessible with a valid user:
If a user is not authorized you can make use of the built in Apollo helper AuthenticationError
to return a suitable response.
Once you have integrated Kinde with your React application using the Kinde React SDK you can enhance it to support the Apollo client.
We recommend creating a specific component in your app to handle the Apollo / Kinde integration:
Then you can use it in your app as follows.
This will ensure every API call to your Apollo server contains the Bearer token provided by Kinde.
If you need any assistance with getting Kinde connected reach out to us at support@kinde.com.