Coder Social home page Coder Social logo

Comments (7)

rkusa avatar rkusa commented on May 12, 2024

I've removed the deprecation warning for now; published as 2.2.2. The user is still accessible through ctx.state.user. @gingerich I am still eager to adhere to Koa's way of doing things. However, I've test implemented workarounds to get passport to work with having the user in ctx.state. But since methods like login() are actively using req.user, the amount of required workarounds is unreasonable high. Maybe an ideal solution can only be achieved by implementing authentication for Koa from scratch. Unfortunately, this is not possible with keeping compatibility to all passport strategies, which would make such an undertaking a tremendous and unreasonable amount of work 😕

from koa-passport.

jeffijoe avatar jeffijoe commented on May 12, 2024

@rkusa not guessing monkey-patching all used strategies would work?

from koa-passport.

rkusa avatar rkusa commented on May 12, 2024

Thanks for the feedback! Since passport is adding things to req anyway, the question would be: what is better, monkey-patching all strategies, or living with having the user property in multiple places. I personally don't like both, what probably prefer the latter. But I am open to hearing other opinions on that!

from koa-passport.

jeffijoe avatar jeffijoe commented on May 12, 2024

@rkusa the best option would be making a different authentication library (clean codebase), but it would be a shame to discard the sheer amount of Passport strategies available.

from koa-passport.

jeffijoe avatar jeffijoe commented on May 12, 2024

Easiest path would be proxying the ctx.req.user getters and setters to ctx.state - that way everyone is happy I guess, and will maintain backward comp with other libraries :shipit:

from koa-passport.

rkusa avatar rkusa commented on May 12, 2024

Yep, in an ideal world we would have a passport written for Koa from scratch. But writing all the strategies again... and going through all security issues again... does not sound too good.

I am currently copying the user value over to ctx.state. A getter and setter would definitely better. Especially since the user on the req is already a getter and setter. However, I ran into a weird bug today and I hadn't the time to debug it, which is why I went for copying for now. I'll replace this by a getter and setter later.

from koa-passport.

rkusa avatar rkusa commented on May 12, 2024

The user object now lives only in one single place, which is ctx.state.user.

from koa-passport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.