ihp icon indicating copy to clipboard operation
ihp copied to clipboard

Initial State Is Sent Back To The SSC

Open s0kil opened this issue 11 months ago • 3 comments

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)

....

s0kil avatar Jul 27 '23 05:07 s0kil

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 avatar Jul 27 '23 06:07 mpscholten

@mpscholten Is this a good approach in the first place, can't we save initial state in some ?context?

s0kil avatar Jul 27 '23 16:07 s0kil

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

mpscholten avatar Jul 27 '23 20:07 mpscholten