tuupola / slim-jwt-auth

PSR-7 and PSR-15 JWT Authentication Middleware
https://appelsiini.net/projects/slim-jwt-auth
MIT License
827 stars 141 forks source link

Slim Error on redirecting from error callback #46

Closed X-Tender closed 7 years ago

X-Tender commented 7 years ago

I have a strange issue. Thats the error callback of the JWT JwtAuthentication (1.x).

"error" => function ($options) use ($app) {
        return $app->redirect( $app->urlFor('index') );
    }

On my development system (mamp php 5.6) the rediect from the "error" callback works fine. On my productions erver (1&1 php 5.6) I get the following error:

Type: Slim\Exception\Stop
File: /SERVERPATH/htdocs/app/vendor_modules/slim/slim/Slim/Slim.php
Line: 1022
Trace

#0 /SERVERPATH/htdocs/app/vendor_modules/slim/slim/Slim/Slim.php(1042): Slim\Slim->stop()
#1 /SERVERPATH/htdocs/app/vendor_modules/slim/slim/Slim/Slim.php(1105): Slim\Slim->halt(302)
#2 /SERVERPATH/htdocs/app/php/start.php(151): Slim\Slim->redirect('/app/public/')
#3 /SERVERPATH/htdocs/app/vendor_modules/tuupola/slim-jwt-auth/src/JwtAuthentication.php(150): {closure}(Array)
#4 /SERVERPATH/htdocs/app/vendor_modules/tuupola/slim-jwt-auth/src/JwtAuthentication.php(97): Slim\Middleware\JwtAuthentication->error(Array)
#5 /SERVERPATH/htdocs/app/vendor_modules/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\JwtAuthentication->call()
#6 /SERVERPATH/htdocs/app/vendor_modules/slim/slim/Slim/Slim.php(1302): Slim\Middleware\PrettyExceptions->call()
#7 /SERVERPATH/htdocs/app/php/start.php(176): Slim\Slim->run()
#8 /SERVERPATH/htdocs/app/public/index.php(2): require('/SERVERPATH/d...')
#9 {main}

What could be wrong?!

tuupola commented 7 years ago

Slim 2 uses exceptions internally for control flow. You are seeing one of these Slim 2 control flow exceptions. Look for differences in your development and production config.

X-Tender commented 7 years ago

Honestly thats not realy any difference except the DB Connect credentials. So I sould better bother the slim developer about the issue :) ?!

tuupola commented 7 years ago

It is Slim which throws the exception, not the middleware.

https://github.com/slimphp/Slim/blob/2.x/Slim/Slim.php#L1102-L1105 https://github.com/slimphp/Slim/blob/2.x/Slim/Slim.php#L1037-L1043 https://github.com/slimphp/Slim/blob/2.x/Slim/Slim.php#L1020-L1023

Why the Exception is ignored on development host and shown on live host I do not know. However quick Google search reveals this.

http://stackoverflow.com/questions/25902650/slim-redirect-works-but-also-throws-an-exception

X-Tender commented 7 years ago

Thanks. I packed it now that way and it works :/ But it feels wrong.

try {
    return $app->redirect( $app->urlFor('index') );
} catch(\Exception $e) {}
tuupola commented 7 years ago

Yeah I agree. I think that was the reason those Exceptions were dropped in 3.x.