question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No access to context in Strategy.

See original GitHub issue

Hello. When I try to get user data in strategy, I can’t get the state data. For example, I need to authenticate user to tether his data of different socials, so in express I’ld need to set passReqToCallback: true in strategy. For now I made a hack in my project- in file lib/framework/request.js I changed exports.create function to this:

  const req = Object.create(ctx.request, properties)

  // add passport http.IncomingMessage extensions
  req.login = IncomingMessageExt.logIn
  req.logIn = IncomingMessageExt.logIn
  req.logout = IncomingMessageExt.logOut
  req.logOut = IncomingMessageExt.logOut
  req.isAuthenticated = IncomingMessageExt.isAuthenticated
  req.isUnauthenticated = IncomingMessageExt.isUnauthenticated
  req.ctx = ctx;
  return req
}

Just added req.ctx=ctx; before return req so I can use ctx in my strategy.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
rkusacommented, Sep 7, 2017

@leebenson Just published (it is a major release because of the passport update to 0.4.x)

3reactions
vsviridovcommented, Feb 22, 2017

I pass the database connection through middlewares via ctx.state so having access to that in the strategy would be nice, for persistence.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Leaders Create the Context for Strategy Execution
This requires, first of all, that everyone has a reasonably shared understanding of the overall strategy; and second, that everyone makes it ...
Read more >
Don't Try to Communicate Strategy Without Context - Gartner
Communications leaders expect managers to spread the word on strategy; make sure they have and share the context employees need.
Read more >
In the strategy pattern can the strategy take the Context as ...
One issue I see with your approach is that there would a tight coupling between the concrete Context class and the instances of...
Read more >
Putting Context Into Strategy Development - L.E.K. Consulting
Strategy is all about choices — coherent choices that fit into an overarching plan to reach an objective. We often use the diagram...
Read more >
Strategy - UNC Computer Science
Context checks to see if it has a Strategy object before accessing it. If there is one, then Context uses it normally. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found