1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crateuse_clerk_context;
use *;
/// Renders `children` when Auth state is signed in. `fallback` is rendered
/// otherwise (or nothing if absent). A plain `Protect` with no role or
/// permission prop renders for signed-in Auth state.
///
/// The `role` and `permission` props are rendering gates backed by
/// server-verified org claims when those claims are present. Role and
/// permission gates fail closed when claims are absent or do not match.
/// Server-side authorization is still required for security-sensitive work.
///
/// Matching Clerk React, `permission` takes precedence when both props are
/// set; the `role` prop is ignored in that case.
///
/// # Behavior while auth is loading
///
/// `Protect` fails closed: it renders `fallback` for every non-signed-in Auth
/// state, including the *loading* state before clerk-js resolves. In a
/// fullstack app that did not seed a signed-in SSR snapshot, an authorized user
/// therefore sees `fallback` briefly, then `children` once auth resolves. This
/// is the safe default (never flash gated content at a not-yet-authorized
/// user), but it can flash the fallback. If you need to distinguish "still
/// loading" from "denied" (e.g. to show a spinner instead of the fallback)
/// read [`use_auth`](crate::use_auth) directly and branch on
/// [`is_loading`](crate::UseAuth::is_loading).
///
/// # Example
///
/// ```no_run
/// use dioxus::prelude::*;
/// use dioxus_clerk::*;
///
/// #[component]
/// fn AdminLink() -> Element {
/// rsx! {
/// Protect {
/// role: "org:admin",
/// fallback: rsx! {},
/// a { href: "/admin", "Admin" }
/// }
/// }
/// }
/// ```