Return response before Authentification

Hello,

What is the right way to filter routes so that slim can render a view before the middleware is applied,

Actually i have set an authentification system using firebase/php-jwt but i want some views to be rendered publicly before authentification.

Thank’s.

How can you render a page, and then make stuff?
You can hide/show some information on a view if the user is auth or not instead.

The problem is that my middleware is blocking all the requests that don’t have a valid token, but how should i do for a first authentification request that obviously dont have a token here’s my code if it helps :

`$app->add(function (Request $request,Response $response, $next) use ($app){
$stringToken = $request->getHeader("Authorization")[0];
if($stringToken == NULL){
    return $response->withJson(array("Connection"=>"Fail On Token", "Error"=>"No token Provided."));
}else{
    $jsonObjectToken = json_decode($stringToken);
    try{
        JWT::decode($jsonObjectToken->jwt, JWTController::$secretKey, array('HS512'));
    }catch (Exception $e){
        return $response->withJson(array("Connection"=>"Fail On Token", "Error"=>$e->getMessage()));
    }
    $response = $next($request, $response);

    return $response;
}

});`

Because the middleware is added to $app it applies for all routes, including the public ones. You can instead add the authorization middleware only to the specific routes that need authorization, for example by using [group middleware].

@llvdl is right.
You should add middleware only where you need.