lightsofapollo/superagent-promise

agent() not exposed

MystK opened this issue · 10 comments

Looks like I can't call superagent.agent() to persist sessions and cookies. Without it, I can't login to a website with redirects. Is there something I'm missing, or is there an alternative to calling superagent.agent()?

Nope, you're not missing anything. No one has needed it so far (or complained about it's absence at any rate).

Simple fix would be to set superagent's agent property after this line

Hey there, not too sure what to put there. I tried:

request.agent = require('./agent');

Where I copied agent and dependencies from superagent, but it's not working.

Can you give an example of how you would use SuperAgent.agent?

var superagent = require('superagent');
var session = superagent.agent();
session.post('/login').send({username:'username',password:'password'}).end(()=>{
  session.get('/posts').end(...)
})

SuperAgent.agent spins off a single session to be used during the navigating lifecycle, especially useful during API mocha-testing. Without using superagent.agent(), each request has cleared headers & such, and the second superagent.get('/posts') would return 401 (if that route is protected). At least, this is how I understand superagent to work (see this stackoverflow)?

Ie, it's used for session-based requests. I too vote for this feature

Ok, I'll have to see how they Superagent does it. Sounds like it could be tricky, but not impossible

+1 Also would be glad to see this feature. It's odd how SuperAgent removed docs of this and example script.

chpio commented

👍 yes please :)

any update on this? Still not exposed, still an issue :)

Damn, ran into this dead end. Looks like I'll need to drop this dead project and upgrade superagent to a later version. They've been supporting Promises since 2.x