kroo / reflex-clerk

A reflex custom component library for clerk
14 stars 7 forks source link

Getting "No Clerk JWT public keys found. Skipping Clerk session set." #5

Open ankitsharp7 opened 3 months ago

ankitsharp7 commented 3 months ago

Hi , I am getting this error :"No Clerk JWT public keys found. Skipping Clerk session set." while running reflex clerk with my reflex app and because of the is certain features are not working as clerk session set is getting skipped. As an example this code is not working -

clerk.clerk_loaded(
                        rx.cond(
                            clerk.ClerkState.is_signed_in,
                            rx.box(
                                rx.text(
                                    "You are currently logged in as ",
                                    clerk.ClerkState.user.first_name
                                ),
                            ),
                            rx.text("you are currently logged out"))),
ankitsharp7 commented 3 months ago

Hi , I debugged a little , it seems the clerk_client is being set automaticall . Only clerkprovider is getting set.

TimChild commented 1 month ago

I was getting the same error and really struggling to figure out why...

Edit: Turns out I am still getting this error and still don't understand why. Below is what I originally thought was the problem.

TLDR; delete the .web directory and re-build.

The demo in this repo was working for me, but when I was trying to implement in my own app, even after reducing my app all the way down to just this demo, the ClerkState was still not getting updated, and I was seeing the No Clerk JWT public keys found. Skipping Clerk session set. error in the console. As soon as I deleted the .web directory and re-built, it worked perfectly.

I'm not exactly sure why this fixed things for me, maybe it was related to having initially built the fronted before setting the clerk api keys correctly.

But, the problem came back, and I don't understand again... I'll hopefully update with an actual solution...

TimChild commented 1 month ago

Ok, I've finally figured out what was actually going on...

TLDR; CLERK_SECRET_KEY environment variable is needed for the ClerkState to work properly.

I generally like to load all my environment variables into an object, and then explicitly use them where necessary (so I can easily see any usages) rather than accessing environment variables directly from various places in code. However, if you take this approach and don't have an environment variable set for the clerk secrent key, and instead pass it into the clerk_provider as an argument, then the ClerkState._secret_key never gets set.

Looking at the ClerkState from lines 119 to 145, you can see that the jwt_public_keys property depends on the clerk_api_client property that depends on the secret_key property, that needs the CLERK_SECRET_KEY environment variable to be set...

I was caught out by the option to provide the secret_key to the clerk_provider function, and assumed that's the only place it was actually necessary.

To add to the confusion, the change only becomes apparent after stopping and restarting the reflex server (hot reloading isn't enough).