I need all routes after /hub/ to be protected by RainLab.User authentification.
That being said, as per the plugin documentation:
Access to routes can be restricted by applying the AuthMiddleware.
Route::group(['middleware' => 'RainLab\User\Classes\AuthMiddleware'], function () {
// All routes here will require authentication
});
I know that. You can put “return ‘hi’;” if you want and you will see hi displayed and not a blank page.
What I was wondering is how can I wrap all my url’s after /hub/ with the Authentification middleware without adding any overhead (redirecting to a view etc.).
If it is a CMS page, I’d suggest - as you found out - to use the Session component, if it’s an API you want to protect you would put all the routes into a group and protect that group with the middleware etc. etc.
Imho the most important aspect is, that the protection and the target to protect are together. e. g. CMS page and Component, routes and middleware - but not CMS pages protected by a middleware.
One thing that might be what you want:
you can extend Rainlabs middleware with a custom plugin, add your middleware to the kernel for all calls, check in the middleware if it’s an URI you want to have protected and then hand off the request to Rainlabs middleware or let it through.