I'm creating a model that I will use to authenticate users for API access, and I have a secret
field where I want to store a Base64
encoded uuid/v4
generated value.
I went through the different field types and options, but still not seeing how I could achieve this.
Is there a way to hook in model instance creation, and set the value of my secret
field ?
Yes, you can use the pre hooks.
In your situation, the basics would be:
That would go before your final
AuthenticationModel.register();
in your model.js file.This is how I set it up, also with the pre-save hook. My problem before was that I was getting the same random number again until I restarted the server.
Using
this.isNew
was also useful in my case.