Comments (7)
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.
from core.
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.
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.
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.
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.
Seems like that's something Flight should be doing when redirect() is called.
from core.
So flight 3.0.2 handles groups now. Hopefully that fixes what you were after?
from core.
Related Issues (20)
- display_errors does not work with flight HOT 4
- Argument #1 ($ex) must be of type Exception, TypeError given HOT 2
- Cors in Framework HOT 5
- describing routes HOT 3
- Slashes In Routes HOT 2
- Website outdated version HOT 1
- I make a new framework βAlightβ, can anyone try it and give me some feedback? HOT 1
- Flushing buffer results in Response->write() error HOT 1
- Migrate to Flight 2 HOT 1
- Future of the Flight Micro Framework HOT 19
- Naming routes - help for navigation HOT 4
- Example projects - What would that look like ? HOT 14
- Possible integration with Roadrunner and Swoole. HOT 2
- Possible way to generate OpenAPI specification on the fly. HOT 1
- Possible deployment on AWS Lambda. HOT 1
- Possible way to include some shorthand helpers or utils. HOT 12
- Documentation on how to Docker-ize FlightPHP application. HOT 1
- Notice: Event 'notFound' has been overridden! HOT 5
- Minifier html HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.