javascript - With Sails.js how can I make /users/me a route that works with associations? -
i have main model accounts, have few has many models notifications , friends
in main.js
i'd able things like:
socket.get('/users/me/notifications');
instead of like:
socket.get('/users/ + g_useraccountid + '/notifications');
^^ works right now, set asynchronously if code loads before g_useraccountid set try use undefined instead bad.. bad..
i understand policies , i'm wondering how can make work rest blueprints , not. if i'm not clear please let me know
is there way without setting findone methods in each controller? automatically fill in /me/ 1
the easiest way can imagine doing without setting findone methods in each controller create policy matches /users/me/notifications route, redirecting current session's user id. potentially use following, , update /config/policy file.
if (session.authenticated) { return res.redirect('/users/' + req.session.user.id + '/notifications'); } if wanted handle anytime /users/me route hit, modify policy, tweak req.url , redirect new 1 uses user id, , apply relevant routes in policy config file, or setup custom middleware handle problem same way.
Comments
Post a Comment