Permalink
Browse files

Example of how to use user-object as a persistent server-side object

  • Loading branch information...
1 parent a6ebb62 commit 46acff665147410c1e142099f9f0403909c97e54 @eirikb eirikb committed Apr 27, 2011
Showing with 5 additions and 4 deletions.
  1. +2 −1 lib/nowServerLib.js
  2. +3 −3 lib/wrap.js
View
@@ -60,7 +60,8 @@ var nowCore = {
// Create proxy object
- nowCore.proxies[client.sessionId] = proxy.wrap(nowCore.constructClientScopeStore(client), scope, client.sessionId);
+ client.user = client.user ? client.user : {clientId: client.sessionId};
+ nowCore.proxies[client.sessionId] = proxy.wrap(nowCore.constructClientScopeStore(client), scope, client.user);
nowCore.scopes[client.sessionId] = scope;
nowCore.clientGroups[client.sessionId] = [];
View
@@ -1,6 +1,6 @@
var Proxy = require('node-proxy');
-exports.wrap = function (store, sessions, clientId) {
+exports.wrap = function (store, sessions, user) {
var taint = {};
var taintedFqns = {};
var set = store ? (store.set || store.save).bind(store) : null;
@@ -13,8 +13,8 @@ exports.wrap = function (store, sessions, clientId) {
else {
var returnObj = wrapRoot(name, sessions[name], '["'+name+'"]', theProxy);
if(typeof returnObj === 'function' && sessions.hasOwnProperty(name)){
- if(clientId){
- returnObj = returnObj.bind({now: theProxy, user:{clientId: clientId}});
+ if(user){
+ returnObj = returnObj.bind({now: theProxy, user:user});
} else {
returnObj = returnObj.bind({now: theProxy});
}

0 comments on commit 46acff6

Please sign in to comment.