Reflex Clerk Component Library Documentation¶
A Reflex custom component library for Clerk ⧉, a User Management Platform.
Getting Started¶
Install with pip install:
pip install reflex-clerk
Import the custom component:
import reflex_clerk as clerk
Install signup and login pages:
import reflex as rx
import reflex_clerk as clerk
app = rx.App()
clerk.install_pages(
app,
publishable_key="pk_my_publishable_key",
signin_route="/signin",
signup_route="/signup"
)
Wrap any pages that use clerk auth components in a
clerk_provider
.
import reflex_clerk as clerk
import reflex as rx
@rx.page("/")
def homepage():
clerk.clerk_provider(
..., # the rest of my homepage
publishable_key="pk_my_publishable_key",
secret_key="sk_my_secret_key"
)
... and now use one of over a dozen components provided by the Clerk SDK, and access the current user with ClerkState.
import reflex_clerk as clerk
import reflex as rx
...
clerk.clerk_provider(
...,
clerk.signed_in( # (1)
rx.cond(
clerk.ClerkState.user.has_image, # (2)
rx.chakra.avatar(
src=clerk.ClerkState.user.image_url, # (3)
name=clerk.ClerkState.user.first_name,
size="xl",
),
)
),
...
)
- The clerk.signed_in() control component hides child components unless the user is actively logged in. See also clerk.signed_out() and clerk.protect.
- ClerkState provides a reflex State that holds the current authentication state, as well as the reflex user itself.
- ClerkState.user contains the Clerk user object for the currently logged in user -- including email and phone number info, name information, and an avatar image.
Components¶
<ClerkProvider />
: Provides session management context to child components<SignInButton />
: Wrap a button or link with this component to make it a sign-in link!<SignOutButton />
: Logs the current user out.<SignUpButton />
: Wrap a button or link to take the user to the signup page.<UserButton />
: A navbar element for the current logged in user, with user switching capabilities.<SignUp />
: A full user registration card<SignIn />
: A login card<UserProfile />
: A full page component for user profile management<SignedIn />
: Hides child components unless the user is signed in<SignedOut />
: Hides child components unless the user is signed out<RedirectToUserProfile />
: Redirects to the user profile page, if rendered<RedirectToSignIn />
: Redirects to the user sign in page, if rendered<RedirectToSignUp />
: Redirects to the user registration page, if rendered<RedirectToOrganizationProfile />
: Redirects to the organization profile page, if rendered<RedirectToCreateOrganization />
: Redirects to the organization creation page, if rendered<MultisessionAppSupport />
: Ensures child components are rerendered after a session switches users in a multi-user session context<ClerkLoading />
: Renders child components only if Clerk has not yet initialized<ClerkLoaded />
: Renders child components only if Clerk has fully initialized<Protect />
: Renders child components only if the user has the specified role or permissions
Reflex State Management¶
ClerkState.is_logged_in
: true if we can verify the current reflex session contains an authenticated Clerk userClerkState.user
: a copy of the Clerk user object retrieved at the time of authentication
Reflex Auth Pages¶
clerk.install_pages
: Installs /signup and /signin pages preconfigured for Clerkclerk.install_signin_page
: Installs /signin page preconfigured for Clerkclerk.install_signup_page
: Installs /signup page preconfigured for Clerk