-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Observe after access #441
Comments
the |
I can't find any configuration for encrypt property in models json file. So one of solutions is to use "before save" to encrypt and "getter" to decrypt... What may work. But When I post the form, data comes as plain text decrypted. And for example I call validation on this property before saving it will try to decrypt property what is not encrypted what will cause an issue. Example: Post form to save data POST secureField - not encrypted Example: Get/Update from database Model query |
This still seems like something that makes sense to have...and not just because every other operation hook has a before/after. For example, if you merge one instance of a model into the other, then having an 'after access' hook would allow you to put a "redirectId" object in the old instance so that outdated references to the old model can be forwarded to the new model. Right now this can be worked around in remote hooks by creating a wrapper module for the model, but is a problem when you start dealing with model relations and other things more tightly integrated into Loopback itself. |
IMO, 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. Could you please open a new issue in loopback requesting the feature for an easy way how to specify a different database representation of the model data?
This looks like reasonable usage of the new hook to me. Perhaps we can call the new hook "loaded"? Just note that making database requests from such hook will incur performance overhead. Ideally, LoopBack should provide a way how to fetch all related data (like your "redirectId") in a single request, either via SQL JOIN or using an appropriate NoSQL alternative. Since we don't support that yet, adding "loaded"/"after access" hook is a reasonable workaround. |
+1 to add |
bugger. I need this functionality. gutted it's not in already. |
+1 to |
+1 to have |
Do we want to supply |
+1 to |
IMO, the hook should be called |
@bajtos fully agreed 👍 |
|
|
Implemented by #599 |
@bajtos @raymondfeng has
|
Nope, we implemented "loaded" hook instead. I can imagine how "after access" hook could be useful. Before it can be implemented, we need to carefully asses what would be the intended behavior for all our data-access methods. If you would like to help with this feature, then please open a new GitHub issue and propose how would "after access" work for each methods listed in https://loopback.io/doc/en/lb3/Operation-hooks.html#overview. Will the hook be triggered or not? What will be the "context" properties for each operation? |
@bajtos I'm having issues with the 'loaded' implementation. If I create a new property on the Here's a sample code snippet:
|
@sidewaiise I am not sure to be honest. Could you please open a new issue and provide us a sample app reproducing the problem per our instructions? This may be a problem of a specific data-access method not honoring the updated |
Add a new hook called
loaded
. It should be triggered whenever model data from the database is returned back to the caller (i.e.find
but alsocreate
orprototype.updateAttributes
) and the context should provide onlyctx.instance
, noctx.data
. For "batch" load likefind
, the hook should be fired multiple times, once for each model instance loaded.The original issue description
I see there is couple of observers such as "access", "create" and etc.
What I need is "after find".
The reason is: I need to encrypt/decrypt data in database.
So basically before save I can encrypt data with the key.
But I can't decrypt data after find.
I've tried with getter/setter but it doesn't work.
The text was updated successfully, but these errors were encountered: