getsentry / sentry-laravel

The official Laravel SDK for Sentry (sentry.io)
https://sentry.io
MIT License
1.24k stars 189 forks source link

laravel-sentry Not working with auth middleware #308

Closed jhoanborges closed 3 years ago

jhoanborges commented 4 years ago

I have a route with the auth middleware: Route::get('/resumen/checkout', 'CheckoutController@index')->name('checkout')->middleware('auth');

but the sentry handler captures this event and it shows a blank screen instead of the login screen- route. I'm using laravel 5.8, sentry/sentry-laravel": "1.5.0" and PHP 7.2.24

stayallive commented 4 years ago

Hi @jhoanborges can you provide a bit more info about this event you mention?

What is the event you are talking about that Sentry is capturing and where is the app crashing to a white screen so I can maybe try and reproduce?

jhoanborges commented 4 years ago
public function report(Exception $exception)
{
    if (app()->bound('sentry') && $this->shouldReport($exception)) {
        app('sentry')->captureException($exception);
    }
    parent::report($exception);
}

https://docs.sentry.io/platforms/php/laravel/#laravel-5x

stayallive commented 4 years ago

Well yeah I understand where you are capturing it 😄 But I don't know what the "error" in the application is?

If you remove the Sentry part from the report method does that fix your blank screen? And when you get the blank screen, anything in your Laravel logs?

jhoanborges commented 4 years ago

If you remove the Sentry part from the report method does that fix your blank screen? YES And when you get the blank screen, anything in your Laravel logs? NO It should catch the exception, but also allow to continue to the middleware route.

stayallive commented 4 years ago

Thank you for that information but that doesn't help me yet to reproduce the error on my Laravel installation, what is the "error" are you "just" logging into you application with a wrong username or password or are you trying to access the protected url as guest and expect a redirect to the login page?

I need some steps so I can try and rebuild your app as simple as possible on my side to figure out where the white page might be coming from. As far as I'm aware nobody else has the issue.

Could you also run php artisan sentry:test for me to make sure Sentry is configured correctly?

jhoanborges commented 4 years ago

@stayallive everything works propertly and i do receive exceptions with sentry. When i attempt to access to a protected route with the Auth middleware, i get a blank screen (no errors no logs)

Route::get('/resumen/checkout', 'CheckoutController@index')->name('checkout')->middleware('auth');

If i remove the following lines, laravel redirects to the login route (which is the expected behavior).

public function report(Exception $exception)
{
    if (app()->bound('sentry') && $this->shouldReport($exception)) {
        app('sentry')->captureException($exception);
    }
    parent::report($exception);
}
stayallive commented 4 years ago

Hi @jhoanborges, I have been testing with your exact setup (Laravel 5.8 + Laravel Sentry) however I am unable to get the white screen happening.

Have you made any changes to your app/Http/Middleware/Authenticate.php?

Could you also share your composer.json file?

jhoanborges commented 4 years ago

No, i did not change the app/Http/Middleware/Authenticate.ph file. This is my composer.json file

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "bumbummen99/shoppingcart": "^2.8",
        "cviebrock/eloquent-sluggable": "4.8.*",
        "davejamesmiller/laravel-breadcrumbs": "5.x",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "~6.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0",
        "msurguy/honeypot": "^1.1",
        "nicolaslopezj/searchable": "1.*",
        "realrashid/sweet-alert": "^2.0",
        "sentry/sentry-laravel": "1.5.0",
        "tucker-eric/eloquentfilter": "1.4.3",
        "yajra/laravel-datatables-oracle": "~9.0",
        "yoeunes/toastr": "^1.2"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^7.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
            "files": [
        "app/Helpers/Helper.php"
    ],
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}
vfineide commented 3 years ago

Having the same issue, Laravel 8 and Backpackforlaravel. Was this solved?

stayallive commented 3 years ago

@vfineide are you also getting a white screen with no output (not even in the storage/logs folder?) when using the auth AND this package for Sentry Laravel?

I have not been able to reproduce and I don't know if @jhoanborges got it solved eventually.

vfineide commented 3 years ago

Hi, yes correct. Also I am using Backpackforlaravel. I am able to make a test exception from artisan, catched in the sentry.io dashboard. The error output does get stored in the error logs. I can also see the logs from the admin view of Laravel/backback, using the https://github.com/Laravel-Backpack/LogManager package.

This package might interfer?

Med vennlig hilsen

Vidar Fineide Tlf 99590245

tir. 29. sep. 2020 kl. 21:01 skrev Alex Bouma notifications@github.com:

@vfineide https://github.com/vfineide are you also getting a white screen with no output (not even in the storage/logs folder?) when using the auth AND this package for Sentry Laravel?

I have not been able to reproduce and I don't know if @jhoanborges https://github.com/jhoanborges got it solved eventually.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/getsentry/sentry-laravel/issues/308#issuecomment-700918501, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC3VUJAZCHZQCQRUVNURMJTSIIVIZANCNFSM4JTYR42Q .

jhoanborges commented 3 years ago

@vfineide are you also getting a white screen with no output (not even in the storage/logs folder?) when using the auth AND this package for Sentry Laravel?

I have not been able to reproduce and I don't know if @jhoanborges got it solved eventually.

I did not. I just dropped it and started using laravel 7 and 8 and everything worked perfectly

stayallive commented 3 years ago

@jhoanborges did you stop using Sentry or did you upgrade to Laravel 7/8 and Sentry worked there?

I unfortunately have not been able to reproduce the issue at any Laravel version or package combi 😞

tony5Dim commented 3 years ago

Take a look of my answer here #443 A mention could be added in the laravel-sentry doc..

stayallive commented 3 years ago

I am closing this issue because of inactivity, if there is still an issue please re-open / open a new issue so we can investigate 👍