ihp
ihp copied to clipboard
Initial State Is Sent Back To The SSC
My attempt at fixing issue https://github.com/digitallyinduced/ihp/issues/936
Send the Initial State To the Browser, And send it back when the component is initialized.
This requires the component to be an instance of FromJSON
and ToJSON
.
module Web.Component.PolicyEditor where
import Web.Component.Prelude
import Data.Aeson.TH
data PolicyEditor
= PolicyEditor
{ maybeFacilityId :: Maybe (Id' "company_facilities")
, maybePolicyId :: Maybe (Id' "facility_policies")
, modalOpen :: Bool
}
deriving (Data, Eq, Show)
$(deriveJSON defaultOptions 'PolicyEditor)
data PolicyEditorController
= OpenModalAction
| CloseModalAction
deriving (Data, Eq, Show)
$(deriveSSC ''PolicyEditorController)
....
This would allow anyone to write any kind of component state which could be insecure. It might be better to cryptographically sign the initial state JSON and then check the signature in the component JSON decoder
@mpscholten Is this a good approach in the first place, can't we save initial state in some ?context
?
Is this a good approach in the first place, can't we save initial state in some ?context?
Yes, this would be even better. AutoRefresh is working similiar to this. So that might be a good inspiration for designing this