node.js - Is it possible to access a session variable directly in a Model in SailsJS -


i have situation i'd use sails' create blueprint on model. however, need access session variable on create:

url: /api/mymodel/create [post]

model: module.exports = {

    adapter: 'mongo',     schema: true,     attributes: {         user: {             model:'user',             required:true,             index:true         },         item: {             model:'item',             required:true,             index:true         },         quantity: {             required:true,             type: 'integer',             defaultsto: 1,             min: 0         },         size: {             required:true,             type:'string'         },         container: {             required:true,             type:'string'         },         datemanuf: {             required:true,             date:true         }     },     beforevalidation:function(values, next) {         /* want automatically set logged in             userid here */          next();     } }; 

i want automatically set value of logged in user session userid in field. have create own custom route/controller action have access "req" field?

it duplicate of sails.js use session param in model, answer no. have few options. can set value in policies, or can rewrite blueprint actions this. require session user attach models , way.

for instance in policy set userid on blueprint create action

req.query.userid = req.session.userid;  

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -