Code Monkey home page Code Monkey logo

Comments (5)

teja42 avatar teja42 commented on May 8, 2024 1

Awesome. Thanks for the feature.

from atreugo.

savsgio avatar savsgio commented on May 8, 2024

Hi @teja42,

Sorry for delayed answer, i have been on vacation.

The authentication middleware must be executed in the two group paths (AuthRouter and UploadRouter) due to you are registering on main router not in group router. So independently, if you declare the auth middleware before or after the group routers or in another sub-package, the execution always be the same, don't mind the declaration order in the code, just the UseAfter or UseBefore.

Execution chain:

  1. Before middleware (Server.Router.UseBefore)
  2. Before middleware (AuthRouter.UseBefore, UploadRouter.UseBefore, ...)
  3. Before filter
  4. View
  5. After filter
  6. After middleware (AuthRouter.UseAfter, UploadRouter.UseAfter, ...)
  7. After middleware (Server.Router.UseAfter)

Because you want execute the authentication middleware in all paths, group paths, etc, right?

from atreugo.

teja42 avatar teja42 commented on May 8, 2024

Sorry for the delayed response

I DONT want the middleware to run for paths start with /auth
I WANT the middleware to run for paths that don't start with /auth

What I ended up doing was I registered the middleware first and if the path starts with /auth then
I called ctx.Next(). If not I performed the authentication and did accordingly. This approach works. Suggest me If there is a better one.

from atreugo.

savsgio avatar savsgio commented on May 8, 2024

At now it's the best solution

But i'm thinking in a new method to simplify that.

Soon, it could be available.

Thanks!

from atreugo.

savsgio avatar savsgio commented on May 8, 2024

Hi @teja42,

I've been released a new version v10.3.0

I added support for skip middlewares in groups and views 🎉

from atreugo.

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.