{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/1226","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/1226/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/1226/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/1226/events","html_url":"https://github.com/strongloop/loopback/issues/1226","id":62786401,"number":1226,"title":"afterValidate operation hook","user":{"login":"drish","id":1730156,"avatar_url":"https://avatars.githubusercontent.com/u/1730156?v=3","gravatar_id":"","url":"https://api.github.com/users/drish","html_url":"https://github.com/drish","followers_url":"https://api.github.com/users/drish/followers","following_url":"https://api.github.com/users/drish/following{/other_user}","gists_url":"https://api.github.com/users/drish/gists{/gist_id}","starred_url":"https://api.github.com/users/drish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drish/subscriptions","organizations_url":"https://api.github.com/users/drish/orgs","repos_url":"https://api.github.com/users/drish/repos","events_url":"https://api.github.com/users/drish/events{/privacy}","received_events_url":"https://api.github.com/users/drish/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":{"login":"bajtos","id":1140553,"avatar_url":"https://avatars.githubusercontent.com/u/1140553?v=3","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2015-03-18T20:04:38Z","updated_at":"2015-03-31T09:34:19Z","closed_at":null,"body":"Hello guys.\r\n\r\nThe docs say the current version does not support `afterValidate` hook, but what about the case where I need to manipulate data after it is validated ?\r\nFor example, after all my fields are validated I'd like to encrypt some of them and persist into datastore. \r\n\r\nCommon hook `model.afterValidate` is deprecated.\r\n\r\nThanks in advance."},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/88014432","html_url":"https://github.com/strongloop/loopback/issues/1226#issuecomment-88014432","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/1226","id":88014432,"user":{"login":"bajtos","id":1140553,"avatar_url":"https://avatars.githubusercontent.com/u/1140553?v=3","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"created_at":"2015-03-31T09:34:18Z","updated_at":"2015-03-31T09:34:18Z","body":">  I need to manipulate data after it is validated ? For example, after all my fields are validated I'd like to encrypt some of them and persist into datastore.\r\n\r\nCan you please elaborate a bit more please? Are you trying to store the property value in an encrypted form and decrypt it on load?\r\n\r\nAs I said in https://github.com/strongloop/loopback-datasource-juggler/issues/441#issuecomment-77531300, hooks are not the right tool for encrypted storage.\r\n\r\n>  The hooks are not the right tool for transparent encryption of model properties (data), because the instance passed to \"before save\" hooks is then returned in the server response. The HTTP client will thus receive encrypted data, unless you implement also an \"after save\" hook that would decrypt them.\r\n\r\nSee https://github.com/strongloop/loopback/issues/1260 for a discussion about the best way how to implement encrypted properties."}}