DEV Community

Cover image for Simplify authentication and monetisation with Clerk and Salable
Salable
Salable

Posted on

Simplify authentication and monetisation with Clerk and Salable

When it comes to rapidly implementing secure authentication in your application, it doesn’t get much simpler than Clerk. Create an account, implement some pre-built components, and you’re done!

So you’ve now got authentication, but you wanted to make a paid product — what next? This is where Salable comes into the picture.

Salable is a platform that allows you to implement flexible licensing/monetisation without all of the headaches. We make it simple to take payments and authorise users in your system.

Clerk allows you to implement auth in hours instead of days, Salable aims to do the same with licensing and payments.

And guess what? They fit together like two peas in a pod.

In Salable, we have the concept of a Grantee — this is anything/anyone that you’d want a license to belong to. It could be a team, it could be an individual user, it could be a Trello board, anything!

Clerk provides us with a userId for our authenticated user. Here is an example of fetching it using the @clerk/clerk-react package:

import { useUser } from '@clerk/clerk-react'const 
{ user } = useUser()const granteeId = user.id
Enter fullscreen mode Exit fullscreen mode

We can now use this granteeId value with any of the Salable SDKs (or our REST API) to start accepting payments.

Let’s look at an example of checking a user’s license capabilities with @salable/js:

import { getGrantee } from '@salable/js';
const { hasCapability } = await getGrantee({  
apiKey: 'your-salable-api-key',  
productUuid: 'your-products-uuid',  
granteeId, // 💡 this is using the `user.id` from Clerk
});
const isUserLicensedToPerformAction = hasCapability('your-capability-name');
Enter fullscreen mode Exit fullscreen mode

And that is all there is to it. You can now use your Clerk authentication setup to accept payments and run license checks for authenticated users.

To learn more about what methods and functionality Salable offers, check out our documentation site.

For any questions on any Clerk and Salable integration tips and tricks, you can visit our Discord channel.

Top comments (0)