-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added middleware #490
Added middleware #490
Conversation
Also, I made some new files in the Service directory; that's my attempt at extending the Fastroute library and trying to improve the syntax with some |
So I managed to improve the syntax a bit. This is how it currently looks like: $routes->createNewRoute('GET', '/', [Some\Controller::class, 'callbackfunction'])->addMiddleware(Middleware\SomeMiddleware::class, Middleware\SomeOtherMiddleware::class); |
I'm not sure if we should replace this check with a middleware: $userId = $this->userPageAuthorizationChecker->findUserIdIfCurrentVisitorIsAllowedToSeeUser((string)$request->getRouteParameters()['username']);
if ($userId === null) {
return Response::createNotFound();
} The |
While the name of this branch is 'add-web-authentication-middleware', this PR also adds a bunch of other middleware outside of authentication (such as checking whether the user has a Jellyfin / Plex token or is an Admin, etc.)
The middleware stuff is in
src/HttpController/Middleware
.The new syntax for a route is as follows:
$routeCollector->addRoute('GET', '<URI>', [[<Class\SomeHandler::class>, '<someMethod>'], 'middleware' => [<someMiddleware::class>,<someOtherMiddleware::class>]]);
.I'll try and see if I can improve the syntax, because it's currently quite ugly IMO. If no middleware is necessary, the old syntax can be used fine; so then the handler shouldn't be in an array.