Skip to content

Commit da2393c

Browse files
authored
Merge pull request #1 from TimChild/add-props
Add props to ClerkProvider (plus some other minor changes)
2 parents c1b591c + a197c67 commit da2393c

File tree

16 files changed

+430
-87
lines changed

16 files changed

+430
-87
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ name: CI
22

33
on:
44
push:
5-
tags:
6-
- "v*.*.*"
5+
# tags:
6+
# - "v*.*.*"
7+
branches: [main]
78
pull_request:
89
branches: [main]
910

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
workflows: ["Publish"]
66
types:
77
- completed
8+
branches: [main]
89

910
concurrency:
1011
group: ${{ github.workflow }}-${{ github.ref }}

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
workflows: ["CI"]
66
types:
77
- completed
8+
branches: [main]
89

910
concurrency:
1011
group: ${{ github.workflow }}-${{ github.ref }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ dist/
66
site/
77
.states/
88
playwright_test_error.png
9-
.prettierignore
9+
.idea

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Test Status](https://github.com/TimChild/reflex-clerk-api/actions/workflows/ci.yml/badge.svg?branch=v0.1.14)
1+
![Test Status](https://github.com/TimChild/reflex-clerk-api/actions/workflows/ci.yml/badge.svg?branch=v0.2.0)
22
![PyPi publish Status](https://github.com/TimChild/reflex-clerk-api/actions/workflows/publish.yml/badge.svg)
33
![Demo Deploy Status](https://github.com/TimChild/reflex-clerk-api/actions/workflows/deploy.yml/badge.svg)
44

@@ -65,3 +65,8 @@ I use [Taskfile](https://taskfile.dev/) (similar to `makefile`) to make common t
6565
- `task run-docs` -- Run the docs locally
6666
- `task test` -- Run tests
6767
- `task bump-patch/minor/major` -- Bump the version (`patch` for a bug fix, `minor` for an added feature).
68+
69+
70+
## TODO:
71+
72+
- How should the `condition` and `fallback` props be defined on `Protect`? They are supposed to be `Javascript` and `JSX` respectively, but are just `str` for now... Is `Javascript` `rx.Script`? And `JSX` `rx.Component`?

clerk_api_demo/clerk_api_demo/clerk_api_demo.py

Lines changed: 103 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
from rxconfig import config
1212

1313
# Set up debug logging with a console handler
14-
logging.basicConfig(level=logging.DEBUG, handlers=[logging.StreamHandler()])
15-
logging.debug("Logging is set up.")
14+
logging.basicConfig(level=logging.INFO, handlers=[logging.StreamHandler()])
15+
# Just a very quick check to see which loggers are actually active in the console
16+
logging.debug("Logging DEBUG")
17+
logging.info("Logging INFO")
18+
logging.warning("Logging WARNING")
1619

1720

1821
load_dotenv()
@@ -589,46 +592,56 @@ def user_profile_demo() -> rx.Component:
589592

590593

591594
def demo_header() -> rx.Component:
592-
return rx.vstack(
593-
rx.heading("Demos", size="6"),
594-
rx.grid(
595-
rx.vstack(
596-
rx.text(
597-
"The demos below are using a development Clerk API key, so you can try out everything with fake credentials."
598-
),
599-
rx.text(
600-
"To simply log in, you can use the email/password combination."
601-
),
602-
),
603-
rx.card(
604-
rx.vstack(
605-
rx.data_list.root(
606-
data_list_item(
607-
"username", rx.code("test+clerk_test@gmail.com")
595+
demo_intro = rx.vstack(
596+
rx.text(
597+
"The demos below are using a development Clerk API key, so you can try out everything with fake credentials."
598+
),
599+
rx.text("To simply log in, you can use the email/password combination."),
600+
)
601+
clerk_user_info = rx.box(
602+
clerk.clerk_loaded(
603+
rx.cond(
604+
clerk.ClerkState.is_signed_in,
605+
rx.card(
606+
rx.hstack(
607+
rx.data_list.root(
608+
data_list_item(
609+
"Clerk user_id", rx.text(clerk.ClerkState.user_id)
610+
),
611+
data_list_item("User button", clerk.user_button()),
608612
),
609-
data_list_item("password", rx.code("test-clerk-password")),
610613
),
614+
),
615+
rx.text("Sign in to see user info."),
616+
)
617+
),
618+
clerk.clerk_loading(rx.spinner(size="3")),
619+
)
620+
621+
test_user_and_pass = rx.card(
622+
rx.vstack(
623+
rx.data_list.root(
624+
data_list_item("username", rx.code("test+clerk_test@gmail.com")),
625+
data_list_item("password", rx.code("test-clerk-password")),
626+
),
627+
rx.hstack(
628+
clerk.signed_in(
629+
clerk.sign_out_button(rx.button("Sign out", data_testid="sign_out"))
630+
),
631+
clerk.signed_out(
611632
rx.hstack(
612-
clerk.signed_in(
613-
clerk.sign_out_button(
614-
rx.button("Sign out", data_testid="sign_out")
615-
)
633+
clerk.sign_in_button(
634+
rx.button("Sign in", data_testid="sign_in")
616635
),
617-
clerk.signed_out(
618-
rx.hstack(
619-
clerk.sign_in_button(
620-
rx.button("Sign in", data_testid="sign_in")
621-
),
622-
clerk.sign_up_button(
623-
rx.button("Sign up", data_testid="sign_up")
624-
),
625-
),
636+
clerk.sign_up_button(
637+
rx.button("Sign up", data_testid="sign_up")
626638
),
627639
),
628640
),
629641
),
630-
columns=rx.breakpoints(initial="1", sm="2"),
631642
),
643+
)
644+
using_demo_instructions = rx.box(
632645
rx.text(
633646
"Or if you want test signing up, you can use any email with ",
634647
rx.code("+clerk_test"),
@@ -650,50 +663,74 @@ def demo_header() -> rx.Component:
650663
),
651664
)
652665

666+
return rx.vstack(
667+
rx.heading("Demos", size="6"),
668+
rx.grid(
669+
demo_intro,
670+
clerk_user_info,
671+
test_user_and_pass,
672+
using_demo_instructions,
673+
columns=rx.breakpoints(initial="1", sm="2"),
674+
spacing="4",
675+
),
676+
)
677+
653678

654679
def index() -> rx.Component:
655680
clerk.register_on_auth_change_handler(State.do_something_on_log_in_or_out)
656681

657-
return clerk.clerk_provider(
658-
rx.box(
659-
rx.vstack(
660-
rx.flex(
661-
demo_page_header_and_description(),
662-
getting_started(),
663-
spacing="7",
664-
direction=rx.breakpoints(initial="column", sm="row"),
665-
),
666-
# rx.button("Dev reset", on_click=clerk.ClerkState.force_reset),
667-
rx.divider(),
668-
demo_header(),
669-
rx.grid(
670-
current_clerk_state_values(),
671-
clerk_loaded_demo(),
672-
on_load_demo(),
673-
on_auth_change_demo(),
674-
user_info_demo(),
675-
links_to_demo_pages(),
676-
user_profile_demo(),
677-
columns=rx.breakpoints(initial="1", sm="2", md="3", xl="4"),
678-
spacing="4",
679-
align="stretch",
680-
),
681-
align="center",
682+
# Note: Using `clerk.wrap_app(...)` instead of `clerk.clerk_provider(...)` here.
683+
return rx.box(
684+
rx.vstack(
685+
rx.flex(
686+
demo_page_header_and_description(),
687+
getting_started(),
682688
spacing="7",
689+
direction=rx.breakpoints(initial="column", sm="row"),
683690
),
684-
height="100vh",
685-
max_width="100%",
686-
overflow_y="auto",
687-
padding="2em",
688-
),
689-
publishable_key=os.environ["CLERK_PUBLISHABLE_KEY"],
690-
register_user_state=True,
691-
secret_key=os.environ.get("CLERK_SECRET_KEY"),
691+
# rx.button("Dev reset", on_click=clerk.ClerkState.force_reset),
692+
rx.divider(),
693+
demo_header(),
694+
rx.grid(
695+
current_clerk_state_values(),
696+
clerk_loaded_demo(),
697+
on_load_demo(),
698+
on_auth_change_demo(),
699+
user_info_demo(),
700+
links_to_demo_pages(),
701+
user_profile_demo(),
702+
columns=rx.breakpoints(initial="1", sm="2", md="3", xl="4"),
703+
spacing="4",
704+
align="stretch",
705+
),
706+
align="center",
707+
spacing="7",
708+
),
709+
height="100vh",
710+
max_width="100%",
711+
overflow_y="auto",
712+
padding="2em",
692713
)
693714

694715

695716
# Add state and page to the app.
696717
app = rx.App()
718+
719+
# This wraps the entire app (all pages) with the ClerkProvider.
720+
clerk.wrap_app(
721+
app,
722+
publishable_key=os.environ["CLERK_PUBLISHABLE_KEY"],
723+
secret_key=os.environ["CLERK_SECRET_KEY"],
724+
register_user_state=True,
725+
# NOTE: Colors customizable via the `Appearance` object. (baseTheme is not yet implemented)
726+
# appearance=Appearance(
727+
# variables=Variables(
728+
# color_primary="#111A27",
729+
# color_background="#C2F3FF",
730+
# ),
731+
# ),
732+
)
733+
697734
# NOTE: Use the `clerk.on_load` to ensure that the ClerkState is updated *before* any other on_load events are run.
698735
# The `ClerkState` is updated by an event sent from the frontend that is not guaranteed to run before the reflex on_load events.
699736
app.add_page(

custom_components/reflex_clerk_api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
clerk_provider,
66
on_load,
77
register_on_auth_change_handler,
8+
wrap_app,
89
)
910
from .control_components import (
1011
clerk_loaded,
@@ -45,4 +46,5 @@
4546
"signed_out",
4647
"user_button",
4748
"user_profile",
49+
"wrap_app",
4850
]

0 commit comments

Comments
 (0)