javascript - Sequelize JS - protecting properties -


var game = sequelize.define('game', {      secretfield: {         type: datatypes.string(45),         validate: {             notempty: true         }     } }, {      gettermethods: {         secretfieldhash: function () {             return crypto.createhash('sha256').update(this.getdatavalue('secretfield')).digest('hex');         }     } }); 

above model example of current model. i'm trying achieve following.

i have 'secretfield' need use in backend code, want show only hashed version of field in frontend.

is possible?

another example problem player model. don't want send password frontend need use in backend (ie. comparison if user entered correct password).

you might forward following (not implemented yet): https://github.com/sequelize/sequelize/issues/1462

for now, overwrite tojson method this:

{   instancemethods: {     tojson: function () {       var resp = this.prototype.tojson();       resp.secretfield = hash(resp.secretfield);        return resp;     }   } } 

in way secret field available backend removed when object converted json , sent end user.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -