Giter Club home page Giter Club logo

Comments (7)

magikstm avatar magikstm commented on June 7, 2024 2

It doesn't. But, it's ok as-is. You may want to handle it differently by possibly adding some logging or the like. It leaves room for the developer to handle it as he wishes.

Ref:
https://github.com/mikecao/flight/blob/2df64f37ea76ce98b97ed327c6b1f5ea2a5df2b0/flight/Engine.php#L547

from core.

n0nag0n avatar n0nag0n commented on June 7, 2024 2

This is one thing I would like to address with flight is the ability to "group" together routes and then assign a middleware, similar to how SlimPHP handles it. It's really great at communicating context of what the routes should be doing without scouring a bunch of files.

from core.

mjisoton avatar mjisoton commented on June 7, 2024 1

Hey,

I'm not sure how other people do it, but I usually have a middleware (in the form of a 'route') to take care of checking and validating an user session. Is basically a route that matches all requests.

Flight::route('*', 'validateSession');

I put that before any other route declaration, and if there's a valid session, then I let the code proceed to the next matched route with a

return true;

If there's no session, then I do a redirect...

Flight::redirect($domain . '/login');

The 'validateSession' is exactly what you might expect: a function that gets a certain cookie from the request. That cookie contains a session token.

function validateSession(){
     $coo = Flight->request()->cookies->getData();
     if(isValid($coo['cookie_name'])){
          return true;
     } else {
          Flight::redirect($domain . '/login');
     }
}

Obviously, there's the problem of infinite redirects. To solve that, I configure a few URLs as 'available without session' (like /login, /recover-password, /change-password, /create-account, etc).
In FlightPHP, there are probably many other ways to do it.

from core.

mario-nexa avatar mario-nexa commented on June 7, 2024 1

Have you tried using exit; on the line immediately after the redirect() ?
This will make sure that any code below does not get executed when we redirect.

from core.

schmeic avatar schmeic commented on June 7, 2024 1

I guess exit is not the best solution, but I'm suggesting that Flight should not be rendering a view after a redirect is called. This is unexpected behavior, and I actually had to create empty data objects for my view because I was object undefined errors.

So, I don't think it's ok as-is.

from core.

schmeic avatar schmeic commented on June 7, 2024

Seems like that's something Flight should be doing when redirect() is called.

from core.

n0nag0n avatar n0nag0n commented on June 7, 2024

So flight 3.0.2 handles groups now. Hopefully that fixes what you were after?

from core.

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.