Clerk State¶
reflex_clerk.ClerkState ¶
Bases: State
A Reflex state object representing the current authenticated session and user; use this state to render details about the currently logged in user.
Example
import reflex_clerk as clerk
clerk.signed_in(
rx.cond(
ClerkState.user.has_image,
rx.chakra.avatar(
src=ClerkState.user.image_url,
name=ClerkState.user.first_name,
size="xl",
),
)
)
Example
import reflex_clerk as clerk
clerk.protect(
rx.fragment("You are logged in as ", clerk.ClerkState.user.first_name),
fallback=rx.text("You need to sign in first!"),
)
Source code in custom_components/reflex_clerk/lib/clerk_provider.py
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
is_signed_in
class-attribute
instance-attribute
¶
is_signed_in: bool = False
True if the user is signed in, False otherwise.
This field is only set to true after server-side validation of the session is complete. Check if this is true before returning sensitive user state from other states.
Example
rx.cond(
clerk.ClerkState.is_signed_in,
rx.text("You are signed in"),
rx.text("You are signed out")
)
Consider using reflex_clerk.signed_in and reflex_clerk.signed_out instead to render different information based on if the user is signed in or not on the client side instead of on the server.
user
class-attribute
instance-attribute
¶
A variable representing the Clerk User of the currently logged in user.
This field is only set to true after server-side validation of the session is complete, and can be disabled for performance reasons using set_fetch_user_on_auth.
user_id
class-attribute
instance-attribute
¶
A variable representing the Clerk User ID of the currently logged in user.
This field is only set to true after server-side validation of the session is complete.
fetch_user ¶
fetch_user()
Fetches ClerkState.user from the clerk backend API, using ClerkState.user_id. Use this Reflex event if you want to force update the clerk user data after a user logs in (such as after modifying their account profile).
Source code in custom_components/reflex_clerk/lib/clerk_provider.py
221 222 223 224 225 226 227 228 229 230 |
|
set_fetch_user_on_auth
classmethod
¶
set_fetch_user_on_auth(fetch_user: bool)
This method is used to control whether the authenticating user should be fetched from Clerk upon successful authentication.
Defaults to true; set this to False if the Clark User object is not being used, as it saves a backend call to Clark every time a user authenticates.
Note
Setting this to True only fetches ClerkState.user once at the time of user authentication. This implementation doesn't automatically detect and update any changes in the underlying user object data, such as email address modifications. Therefore, to ensure you have the latest user data while logged in, especially if changes have been made, you should use the ClerkState.fetch_user reflex event to manually refresh the user data.
Parameters:
-
fetch_user
(bool
) –Indicates whether the user should be fetched.
Source code in custom_components/reflex_clerk/lib/clerk_provider.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
reflex_clerk.User ¶
Bases: BaseModel
Represents a user object with various attributes related to their profile, authentication, and metadata.
See the Clerk documentation ⧉ for more details.
Attributes:
-
id
(str
) –A unique identifier for the user.
-
object
(str
) –The type of object, typically 'user'.
-
external_id
(Optional[str]
) –An optional external identifier for the user.
-
primary_email_address_id
(Optional[str]
) –The unique identifier for the EmailAddress that the user has set as primary.
-
primary_phone_number_id
(Optional[str]
) –The unique identifier for the PhoneNumber that the user has set as primary.
-
primary_web3_wallet_id
(Optional[str]
) –The unique identifier for the Web3Wallet that the user signed up with.
-
username
(Optional[str]
) –The user's username.
-
first_name
(Optional[str]
) –The user's first name.
-
last_name
(Optional[str]
) –The user's last name.
-
profile_image_url
(Optional[str]
) –Holds the default avatar or user's uploaded profile image. Compatible with Clerk's Image Optimization.
-
image_url
(Optional[str]
) –The URL of the user's profile image.
-
passkeys
(Optional[List[PasskeyResource]]
) –An array of passkeys associated with the user's account.
-
has_image
(bool
) –A boolean to check if the user has uploaded an image or one was copied from OAuth. Returns false if Clerk is displaying an avatar for the user.
-
public_metadata
(Dict[str, Any]
) –Metadata that can be read from the Frontend API and Backend API and can be set only from the Backend API.
-
private_metadata
(Optional[Dict[str, Any]]
) –Metadata that can be read and set only from the Backend API.
-
unsafe_metadata
(Dict[str, Any]
) –Metadata that can be read and set from the Frontend API. Often used for custom fields attached to the User object.
-
email_addresses
(List[EmailAddress]
) –An array of all the EmailAddress objects associated with the user, including the primary.
-
phone_numbers
(List[PhoneNumber]
) –An array of all the PhoneNumber objects associated with the user, including the primary.
-
web3_wallets
(List[Web3Wallet]
) –An array of all the Web3Wallet objects associated with the user, including the primary.
-
saml_accounts
(List[SAMLAccount]
) –An experimental list of SAML accounts associated with the user.
-
password_enabled
(bool
) –A boolean indicating whether the user has a password on their account.
-
two_factor_enabled
(bool
) –A boolean indicating whether the user has enabled two-factor authentication.
-
totp_enabled
(bool
) –A boolean indicating whether the user has enabled TOTP by generating a TOTP secret and verifying it via an authenticator app.
-
backup_code_enabled
(bool
) –A boolean indicating whether the user has enabled Backup codes.
-
last_sign_in_at
(Optional[int]
) –The date when the user last signed in, may be empty if the user has never signed in.
-
banned
(bool
) –A boolean indicating whether the user is banned.
-
locked
(bool
) –A boolean indicating whether the user is locked.
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
|
reflex_clerk.clerk_client.clerk_response_models.PasskeyResource ¶
Bases: BaseModel
Represents a passkey associated with a user response.
Attributes:
-
id
(str
) –The passkey's unique ID generated by Clerk.
-
verification
(Verification
) –Verification details for the passkey.
-
name
(str
) –The passkey's name.
-
created_at
(str
) –The date and time when the passkey was created.
-
updated_at
(str
) –The date and time when the passkey was updated.
-
last_used_at
(str
) –The date and time when the passkey was last used.
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
reflex_clerk.clerk_client.clerk_response_models.EmailAddress ¶
Bases: BaseModel
Represents an email address associated with a user.
Attributes:
-
id
(str
) –A unique identifier for this email address.
-
email_address
(str
) –The value of this email address.
-
verification
(Optional[Verification]
) –An object holding information on the verification of this email address.
-
linked_to
(List[IdentificationLink]
) –An array of objects containing information about any identifications that might be linked to this email address.
-
created_at
(int
) –Unix timestamp of creation
-
updated_at
(int
) –Unix timestamp of latest update
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
reflex_clerk.clerk_client.clerk_response_models.PhoneNumber ¶
Bases: BaseModel
Represents a phone number associated with a user.
Attributes:
-
id
(str
) –A unique identifier for this phone number.
-
phone_number
(str
) –The value of this phone number, in E.164 format ⧉.
-
reserved_for_second_factor
(Optional[bool]
) –Set to true if this phone number is reserved for multi-factor authentication (2FA). Set to false otherwise.
-
default_second_factor
(Optional[bool]
) –Marks this phone number as the default second factor for multi-factor authentication(2FA). A user can have exactly one default second factor.
-
verification
(Optional[Verification]
) –An object holding information on the verification of this phone number.
-
linked_to
(List[IdentificationLink]
) –An object containing information about any other identification that might be linked to this phone number.
-
created_at
(int
) –Unix timestamp of creation
-
updated_at
(int
) –Unix timestamp of latest update
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
reflex_clerk.clerk_client.clerk_response_models.Web3Wallet ¶
Bases: BaseModel
Represents a Web3 wallet address associated with a user.
The address can be used as a proof of identification for users.
Web3 addresses must be verified to ensure that they can be assigned to their rightful owners. The verification is completed via Web3 wallet browser extensions, such as Metamask ⧉. The Web3Wallet3 object holds all the necessary state around the verification process.
Attributes:
-
id
(str
) –A unique identifier for this web3 wallet.
-
web3_wallet
(str
) –In Ethereum ⧉, the address is made up of 0x + 40 hexadecimal characters.
-
created_at
(int
) –The date and time when the passkey was created.
-
updated_at
(int
) –The date and time when the passkey was updated.
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
reflex_clerk.clerk_client.clerk_response_models.SAMLAccount ¶
Bases: BaseModel
Represents a SAML account associated with a user.
Attributes:
-
id
(str
) –A unique identifier for the SAML account.
-
object
(str
) –The type of object, typically 'saml_account'.
-
provider
(str
) –The SAML provider associated with the account.
-
active
(bool
) –A boolean indicating whether the SAML account is active.
-
email_address
(str
) –The email address associated with the SAML account.
-
first_name
(Optional[str]
) –The first name of the user associated with the SAML account.
-
last_name
(Optional[str]
) –The last name of the user associated with the SAML account.
-
provider_user_id
(Optional[str]
) –An optional identifier for the user within the SAML provider.
-
public_metadata
(Dict[str, Any]
) –Metadata for the SAML account.
-
verification
(Optional[Verification]
) –An optional verification object associated with the SAML account.
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
reflex_clerk.clerk_client.clerk_response_models.Verification ¶
Bases: BaseModel
Represents the verification details of an email address or phone number.
Attributes:
-
strategy
(Optional[Literal['oauth_google', 'oauth_mock', 'admin', 'phone_code', 'email_code', 'reset_password_email_code', 'web3_metamask_signature']]
) –The strategy pertaining to the parent sign-up or sign-in attempt.
-
status
(Optional[Literal['unverified', 'verified', 'transferable', 'failed', 'expired']]
) –The state of the verification.
-
attempts
(Optional[int]
) –The number of attempts related to the verification.
-
expire_at
(Optional[int]
) –The time the verification will expire at.
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
reflex_clerk.clerk_client.clerk_response_models.IdentificationLink ¶
Bases: BaseModel
Represents a link between an email address or phone number and another identification type.
Attributes:
-
type
(Literal['oauth_google', 'oauth_mock', 'saml']
) –One of "oauth_google", "oauth_mock", or "saml"
-
id
(str
) –A unique identifier for this link.
Source code in custom_components/reflex_clerk/clerk_client/clerk_response_models.py
55 56 57 58 59 60 61 62 63 64 |
|