Kinde auth integration example

Hi All,

I don’t have time to make a full auth plugin, but here is an example repo using Kinde auth.

This demo was made by following the custom auth instructions on the RedwoodJS website.

Basically, we are wrapping the Redwood Auth package around the Kinde Javascript SDK

Basics…

Add the following to your .env file:

KINDE_DOMAIN="Your Kinde Domain"
KINDE_CLIENT_ID="Your Kinde Client ID"
KINDE_REDIRECT_URI=http://localhost:8910/
KINDE_LOGOUT_REDIRECT_URI="http://localhost:8910"

Don’t forget to add these env vars to your includeEnvironmentVariables in your redwood.toml file.

The main files to pay attention to are the auth.ts file in the web/src/ directory and the auth.ts file in the api/src/lib/ directory.

On the API side we are decoding the JWT Access token that gets sent along with each graphql request. This JWT (Kinde Access token) is used to populate currentUser/getCurrentUser() object from the useAuth hook.

You will need to add whatever information you require in a JWT token in the Kinde Dashboard. See instructions here

It’s not possible to add a first and last name to the access token in the Kinde Dashboard. This means you can not see the first and last name on the currentUser/getCurrentUser function.

The first and last name are surfaced by using userMetadata from the useAuth hook, along with any other data that you have added to the user token.

This example also deals with roles. If you are using roles make sure these are exposed in your access token. You can use the hasRole function from the useAuth hook to check if a user has a specific role and also protect your graphql queries with the requireAuth function. More on redwood roles here..

Have fun!

Nice work @shansmith01 !

The Redwood team is revisiting auth as we enable middleware suppprt so can use auth in SSR and RSC.

I’d heard good things about Kinde and we’ll have to reach out to them for an official provider.

Glad it’s working well!

Cool. FYI they said they are getting quite a few people mention redwoodjs and they are keen on an official integration, they just didn’t have time at the moment.

I must also say they are just really nice people. Interesting roadmap as well.

Might you say… “kinde” people.

Sorry. Had to. :slight_smile:

Great to hear. I think I know someone who can connect me with them.

1 Like