View Source Turnstile (phoenix_turnstile v1.1.2)
Use Cloudflare Turnstile in Phoenix. Check out the README to get started.
Link to this section Summary
Functions
Refreshes the Turnstile widget in a LiveView.
Removes the Turnstile widget from a LiveView.
Renders the Turnstile script tag.
Returns the configured secret key.
Returns the configured site key.
Calls the Turnstile verify endpoint with a response token.
Renders the Turnstile widget.
Link to this section Functions
Refreshes the Turnstile widget in a LiveView.
Since the widget uses phx-update="ignore"
, this function can be used if the widget needs to be
re-mounted in the DOM, such as when the verification fails. If there are multiple Turnstile
widgets on the page and you only want to refresh one of them, pass a DOM ID as the second
argument. Otherwise they will all be refreshed.
Removes the Turnstile widget from a LiveView.
Since the widget uses phx-update="ignore"
, this function can be used if the widget needs to be
removed from the DOM. If there are multiple Turnstile widgets on the page and you only want to
refresh one of them, pass a DOM ID as the second argument. Otherwise they will all be removed.
Renders the Turnstile script tag.
Uses explicit rendering so it works with hooks. Additional attributes will be passed through to the script tag.
Returns the configured secret key.
Returns the configured site key.
Calls the Turnstile verify endpoint with a response token.
Expects a map with string keys that contains a value for "cf-response-token"
(see
verification for more info). The remote IP can be passed for extra
security when running the verification, but is optional. Returns {:ok, response}
if the
verification succeeded, or {:error, reason}
if the verification failed.
Renders the Turnstile widget.
attributes
Attributes
:id
- The ID of the element. Defaults to"cf-turnstile"
.:class
- The class name passed to the element. Defaults tonil
.:hook
- The phx-hook used. Defaults to"Turnstile"
.:sitekey
- The Turnstile site key. Defaults to the:site_key
config value.:events
- An atom list of the callback events to listen for for in the Live View. See events.
All other attributes will be passed through to the element as data-*
attributes so the widget
can be customized. See the Turnstile docs
for a list of available attributes.