Code Monkey home page Code Monkey logo

Comments (1)

jackharrhy avatar jackharrhy commented on August 29, 2024
[22:51] <i>jack arthur null</i>: so i went down the route of looking into doing the auth via a validation middleware
[22:51] <i>jack arthur null</i>: but there's no real way for the controller to know if the session was set
[22:51] <i>jack arthur null</i>: so say if through some dev. error you miss out adding the middleware
[22:51] <i>jack arthur null</i>: there'd be no error on the end of the controller that gets called without the userId being set
[22:52] <i>jack arthur null</i>: tbh, since it's already only a single call to a function in the routes, i think keeping it as is for now is all we can do
[22:52] Mudkip: could you not hang the userid as a request param for all requests
[22:52] Mudkip: and then just have if !userid exit
[22:52] Mudkip: or wait
[22:52] <i>jack arthur null</i>: some routes don't need login though
[22:53] Mudkip: can middlewares not just 403 the requests themselves?
[22:53] <i>jack arthur null</i>: they can
[22:53] Mudkip: there must be some mechanism through the routes to exclude
[22:53] Mudkip: laravel has that :smile:
[22:55] <i>jack arthur null</i>: basically you'd still need a check in the controllers for having a valid session
[22:55] <i>jack arthur null</i>: which isn't much different than whats already there
[22:55] Mudkip: https://javascript.plainenglish.io/excluding-routes-from-calling-express-middleware-with-express-unless-3389ab4117ef
[22:55] Mudkip: Kinda meh it being a seperate package
[22:56] <i>jack arthur null</i>: like you'd have a route:

POST /bookmarks
that right now is just:

-> create bookmark controller
[22:56] <i>jack arthur null</i>: but if you added the middleware, you'd have

middleware -> create bookmark controller
[22:57] <i>jack arthur null</i>: but there's no compile time way to ensure that the first middle ware comes first
[22:57] <i>jack arthur null</i>: so you'd have to basically check to see if the previous middleware did the job of getting the userId setup
[22:57] Mudkip: wait what
[22:57] Mudkip: Middleware order is not enforced :/?
[22:58] Mudkip: compile time
[22:58] Mudkip: that sounds like such a weird problem, ngl
[22:58] <i>jack arthur null</i>: not really about order, but if you say forgot to add the first middleware, there'd be no way to verify
[22:58] Mudkip: But why would you forget to add a middleware
[22:58] Mudkip: You include all and do exclusions
[22:58] Mudkip: its an api
[22:59] Mudkip: idk, maybe im thkinking about it wrong
[22:59] Mudkip: I have implemented a similar setup before
[22:59] <i>jack arthur null</i>: if ensuring the users session was anything more than two lines of code i'd be down to middleware it, but since its just:
const userId = await expectUserId(req);

i think its ok to leave as is
[22:59] Mudkip: fair point
[22:59] <i>jack arthur null</i>: since expectUserId does all the job of throwing errors for you

from yamun.

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.