Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): add Clerk plugin to manage users with webhooks #91

Merged
merged 3 commits into from
Feb 27, 2025

Conversation

jeroenptrs
Copy link

@jeroenptrs jeroenptrs commented Feb 23, 2025

Purpose

Heavily based on the Stripe plugin, this plugin adds support for Clerk webhooks to insert user data into a table to link users to any data (like Stripe subscriptions, as also apparently this Clerk roadmap item is a Stripe integration)

I've doubted between contributing this as a PR and a userland npm/jsr package, but as there's stripe and slack plugins too, it made sense to include it here. Besides, it also depends on the SQL file support I added in #89 😅

That said, not necessarily needed for discussion here, but the plugin system could potentially be extracted and collected in an awesome-starbase repo?

Tasks

  • minor clean up in pnpm lockfile that was causing pnpm install --frozen-lockfile to error
  • add clerk plugin that inserts / deletes users / sessions following Clerk events
  • add an authenticate function to the plugin that verifies a user session
  • fill in reviewer info and show a little demo down below

Verify

  • instantiate the Clerk plugin and add it to the plugins in src/index.ts
  • create a Clerk instance (development is fine for testing)
  • follow their guide on local webhook development using ngrok or deploy the worker
  • add a webhook as well as copy over the signing secret you receive to the plugin
  • optional grab the instance id from settings and add it as well
  • create, modify and delete a user and all changes should persist!

Result

Screenshot 2025-02-24 at 07 51 56 Screenshot 2025-02-24 at 07 52 15

I quickly tested with ngrok because I've been working on setting up these webhooks in a project of mine as well 😅

@jeroenptrs jeroenptrs marked this pull request as draft February 23, 2025 21:51
@jeroenptrs jeroenptrs marked this pull request as ready for review February 24, 2025 07:05
@Brayden Brayden added the enhancement New feature or request label Feb 24, 2025
@Brayden
Copy link
Member

Brayden commented Feb 24, 2025

Thanks for this contribution. It's been on my list for a while to make a more official integration with Clerk as a plugin so your good intuition worked out here. I'll work on taking a closer look at this and doing some testing on my end hopefully today and be able to report back. Greatly appreciate this PR :)

the plugin system could potentially be extracted and collected in an awesome-starbase repo?

This is something that has been swirling around in my head as well if we need to move them into their own repository, or if it's more desirable that they're available in the core project too. Still haven't solidified the right answer here but nonetheless I like where your head is at here!

@Brayden
Copy link
Member

Brayden commented Feb 24, 2025

@jeroenptrs Plugin works like a charm, just as described!

Eventually it would be great to bring over session events from Clerk as well and a way to verify session auth tokens are valid by checking with something like the JWKS endpoint in clerk. This could eventually work well with the RLS capabilities we're working on productionizing within Starbase as well.

I know this PR is dependent on #89 as well so will review that PR before approving this one. Great work 👏

@jeroenptrs
Copy link
Author

Eventually it would be great to bring over session events from Clerk as well and a way to verify session auth tokens are valid by checking with something like the JWKS endpoint in clerk. This could eventually work well with the RLS capabilities we're working on productionizing within Starbase as well.

Sounds to me like using Clerk's own hono middleware could also fit the bill?

Reading up on verifying in starbase, this should be feasible quite easily and removes the dependency of doing a call to Clerk altogether if users just configure the PEM Public Key instead. Wdyt?

@jeroenptrs jeroenptrs force-pushed the feat/clerk-plugin branch 5 times, most recently from 5cb03b6 to d79c314 Compare February 24, 2025 23:23
@jeroenptrs
Copy link
Author

FYI updated the PR with functionality to verify user sessions inside of the plugin (no external calls to Clerk needed, so this goes pretty swiftly!

Jeroen Peeters added 2 commits February 25, 2025 15:28
@jeroenptrs jeroenptrs force-pushed the feat/clerk-plugin branch 2 times, most recently from d47e4a6 to b56d6ea Compare February 25, 2025 18:44
Copy link
Member

@Brayden Brayden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for working so hard on getting this over the finish line 🚀

@jeroenptrs
Copy link
Author

@Brayden nice, for me it's also ready to merge then!

@Brayden Brayden merged commit 354d80a into outerbase:main Feb 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants