Migration Guide
This guide provides information on migrating from the Kroo/reflex-clerk package to the reflex-clerk-api. It's mostly a direct drop-in replacement, but there are a few small changes to be aware of. Also some improvements that fill some gaps in the previous package.
Key Changes
-
Import Path Update: Update your imports to use
reflex_clerk_apiinstead ofreflex_clerk. -
Page Installation: Use
clerk.add_sign_in_page(app)andclerk.add_sign_up_page(app)instead ofclerk.install_pages(app). -
User Information Retrieval: For full user info, use
await clerk.get_user()inside event handlers instead ofclerk_state.user. This makes the user data retrieval occur explicitly when needed. You can choose to cache the information however you like. -
ClerkUser: If you just want basic user information, you can enable the
ClerkUserstate by settingregister_user_state=Truewhen callingclerk.clerk_provider(...). -
On load Event Handling: Wrap
on_loadevents that depend on the user authentication state withclerk.on_load(<on_load_events>)to ensure theClerkStateis updated before otheron_loadevents. This ensures thatis_signed_inwill be accurate. (This was not handled with the previous package). -
On Auth Change Handlers: Use
clerk.register_on_auth_change_handler(<handler>)to register event handlers that are called on authentication changes (login/logout). (This was not handled with the previous package). -
Backend API: Note that you can also import and directly use the
clerk_backend_apiif desired, as it is a dependency of this plugin. Theclientused by theClerkStateis available as a propertyclerk_state.client.
Note
The lower case clerk_state implies using clerk_state = await self.get_state(clerk.ClerkState) within an event handler method.