Skip to content
This repository

Sessions are not saved when using Connect.session() middleware. #39

Closed
wants to merge 1 commit into from

4 participants

Travis Tidwell Pavan Kumar Sunkara Charlie Robbins David Lopes
Travis Tidwell

I am working on getting FlatIron to play nicely with Passport.js with https://github.com/travist/flatiron-passport.

I noticed that the session saving fails with OAuth because https://github.com/senchalabs/connect/blob/master/lib/middleware/session.js#L274 tries to inject itself before the end method is called. However this is attached to the this pointer of the request object and not this.res.

This can all be fixed if we just check to see if the end method is attached to this, and call it instead if it is... If not, then fallback to current behavior.

Pavan Kumar Sunkara

I will look into this soon. Thanks.

Pavan Kumar Sunkara

@travist Can you post an example so that I can test this?

Sorry for the delay.

Charlie Robbins
Owner

This is a bug in the original implementation of redirect. It has been fixed in HEAD

Charlie Robbins indexzero closed this November 12, 2012
David Lopes

As of Union version 0.3.5 res is renamed response like so:
this.response.end();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 11 additions and 4 deletions. Show diff stats Hide diff stats

  1. 15  lib/response-stream.js
15  lib/response-stream.js
@@ -162,17 +162,24 @@ ResponseStream.prototype.write = function (data) {
162 162
 
163 163
 ResponseStream.prototype.redirect = function(path, status) {
164 164
   var url = '';
165  
-  
  165
+
166 166
   if(~path.indexOf('://')) {
167 167
     url = path;
168 168
   } else {
169 169
     url += this.req.connection.encrypted ? 'https://' : 'http://';
170 170
     url += this.req.headers.host;
171  
-    url += (path[0] === '/') ? path : '/' + path; 
  171
+    url += (path[0] === '/') ? path : '/' + path;
172 172
   }
173  
- 
  173
+
174 174
   this.res.writeHead(status || 302, {
175 175
     'Location': url
176 176
   });
177  
-  this.res.end();
  177
+
  178
+  // Prefer this.end over this.res.end so that connect.session will save.
  179
+  if ((typeof this.end)==='function') {
  180
+    this.end();
  181
+  }
  182
+  else {
  183
+    this.res.end();
  184
+  }
178 185
 };
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.