Security
Superglue stores your content in memory. If you were to navigate using a normal HTML link or form that does a full page reload the state would be destroyed.
Tip
Superglue does store the following in History.state for convience:
Authentication¶
You can use any Rails authentication system; Devise, Authentication Zero, etc. Superglue leverages standard Rails patterns - routes, controllers, and views - making it friendly with the Rails ecosystem.
Logging out¶
When implementing a logout button use a normal HTML link or form that does a full page reload. This will clear out Superglue's state in memory.
✅ Do
❌ Don't
Navigational formats¶
When working with Devise, be sure to enable json
as a navigational format
CSRF Protection¶
Forms¶
Superglue comes with form_props to build forms. Like its Rails counterpart,
form_with
, form_props
generates a CSRF token per form.
For example, the below would create two forms with unique CSRF tokens each:
json.updateFormA do
form_props(model: @post) do |f|
f.submit
end
end
json.updateFormB do
form_props(model: @post) do |f|
f.submit
end
end
remote
and visit
¶
Both functions will use a CSRF token generated at the page
level when used with a non-GET request. This CSRF token can be accessed from the
state returned from the useSuperglue hook
and gets updated on each page response received. You can also make use of this
state for your own custom fetch
calls.