laravel / fortify

Backend controllers and scaffolding for Laravel authentication.

Home Page:https://laravel.com/docs/fortify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Routes not working if users table is not empty

paulbalan opened this issue · comments

  • Fortify Version: 1.13
  • Laravel Version: 9.19
  • PHP Version: 8.0.2
  • Database Driver & Version:

Description:

Views are set to false in fortify.php
The following error message is thrown when calling with post any fortify endpoints. The endpoint work fine if the users database is empty.

{
    "message": "",
    "exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
    "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\AbstractRouteCollection.php",
    "line": 44,
    "trace": [
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
            "line": 162,
            "function": "handleMatchedRoute",
            "class": "Illuminate\\Routing\\AbstractRouteCollection",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 680,
            "function": "match",
            "class": "Illuminate\\Routing\\RouteCollection",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 667,
            "function": "findRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 656,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 167,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 141,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull.php",
            "line": 31,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TrimStrings.php",
            "line": 40,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TrimStrings",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance.php",
            "line": 86,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Middleware\\HandleCors.php",
            "line": 49,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Http\\Middleware\\HandleCors",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Middleware\\TrustProxies.php",
            "line": 39,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Http\\Middleware\\TrustProxies",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 116,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 142,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 111,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\public\\index.php",
            "line": 52,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "C:\\clicker-app\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\resources\\server.php",
            "line": 16,
            "function": "require_once"
        }
    ]
}

Steps To Reproduce:

I try calling /register from Postman. If the users table from the database is empty it works perfectly fine. If there is at least one user added by a previous call to the endpoint the error is thrown. None of the fortify specific endpoints are working.

Heya, thanks for reporting.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as separate commits on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

Thanks for the quick reply. Here is the repo https://github.com/paulbalan/bug-report

It's pretty much a default Laravel instalation + Fortify. The only changes I made are listed in the latest commit.

Thanks @paulbalan. Do you also have a curl request I can use?

Sure thing. @driesvints

curl --location --request POST 'http://127.0.0.1:8000/register' \ --header 'X-XSRF-TOKEN: eyJpdiI6Ik1SS2JRa0ZpUytxemVMK2JpTnV6dGc9PSIsInZhbHVlIjoidExSR2VZK2M0L2dpVzNzTGsvbFArZHY1V0tVVVFvWmNHdVpGbGRPZmJmWHZaZllmcWl0YVRwaGlDWEcwSUFma1doYmFmOFVxT01tSnZoL3NNK3V6Tm1qWU5WdGdUdnBsb2kweFI0Qkxpb3NGM0FBRTk1czg1MENLVG9oNDlzUDMiLCJtYWMiOiJiZmViMjkzYzU5MTI4OTkxOWI0NmM2OGRlYWRmNGE5NWYwOTU1MmNlNTdlOWUyZTM0NzUyNzYyNGNjY2Y1NTVhIiwidGFnIjoiIn0' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'Cookie: XSRF-TOKEN=eyJpdiI6IjB1di9hOEVqVkJUcnJpR2hMTThUM0E9PSIsInZhbHVlIjoicHVSOGphRzI4Mi92WEs0ZTJ4ZjhNNTF5M25udDVSbGFXSVdGZU5Vb0FOOWwxT3hxSmEwZnRYeDFWSVQxMTMwb1VadUpraks2NUVmZS9CVTQ5SXVDM3E3a1BWZUljZVdlRld4Q1NnLzNDWU5MWUdaRnNKQy9BT3pQVnVyNFphTkoiLCJtYWMiOiI4OWRkMjJhZjQyOGQ5NjRiYjgzZjc5OGRkZjI0MWQzN2IyOGE3MjQyYTQyM2M1NDc2ZWMwMTdiOTlhZjRhNDAzIiwidGFnIjoiIn0%3D; laravel_session=eyJpdiI6IlBlUUJqTmF6bFdYWFZOdjZNY0R1eWc9PSIsInZhbHVlIjoibVlDK2JnV2NzampXNkJLemVpSVhKVmg5VkRjd1d2eFQ3WndyNE9vYzd2VEVaWUNaR1BjYlM5ZU1rZUVWU1FoVWlNb0lTY3h0Rmxic2lZU2FOaVUvUGw3L3RhL2hOcytUQ0tIUjRXYkVYa1FEQkhnaFlXS0UyakZpUXhLVVc4clYiLCJtYWMiOiJiMTE4ZTA4YmM0MTJlYmI1MTg2NTlmY2IzNzhlZWVmMjgwMGJiYTYyY2QxMjQ0ZjljNDZmOGVkZDRjNzY1NjZmIiwidGFnIjoiIn0%3D' \ --data-raw '{ "name": "Paul", "email": "test@test.com", "password": "123456789", "password_confirmation": "123456789" }'

Hey @paulbalan, thanks, that was helpful. I tried it out but didn't get the issues you were experiencing. I disabled the CSRF token check for this but other than that everything seems to work fine:

main $ echo -n '{ "name": "Paul", "email": "test@test.com", "password": "123456789", "password_confirmation": "123456789" }' | http POST http://127.0.0.1:8000/register --json            ~/Sites/test-bug-fortify
HTTP/1.1 201 Created
Cache-Control: no-cache, private
Connection: close
Content-Type: application/json
Date: Thu, 08 Sep 2022 15:19:01 GMT
Date: Thu, 08 Sep 2022 15:19:01 GMT
Host: 127.0.0.1:8000
Set-Cookie: laravel_session=eyJpdiI6IlV2Y0dpTWtNQUg2OEJ6ZzNvWWFlU2c9PSIsInZhbHVlIjoiRjlXYkhNZXRNSlhUQ3Z6ay8yS0NreTBWUkFSZmxSMEgwZXZsS0xuWWRIaXdWaXVDc3YxVDllemtRaTU0UVYvYmhjd0w2eENJK1ZxZnZCQkR0am1WWHNTSFM2SkV0N1NPWVh6TVdkaTFJMjFnYU03V2RrWFdrMnFSODBiUmVNaWkiLCJtYWMiOiJjYzUxZTRiNTIwNDNhOWZkMzc3OTdhODZjZmFmMTYzYmY2MzFiZDMyNWRkM2NkNGI0ZDM3NjE3YjY1MWY3Mjg5IiwidGFnIjoiIn0%3D; expires=Thu, 08-Sep-2022 17:19:01 GMT; Max-Age=7200; path=/; httponly; samesite=lax
X-Powered-By: PHP/8.1.10

""


main $ echo -n '{ "name": "Paul", "email": "test@test.com", "password": "123456789", "password_confirmation": "123456789" }' | http POST http://127.0.0.1:8000/register --json            ~/Sites/test-bug-fortify
HTTP/1.1 422 Unprocessable Content
Cache-Control: no-cache, private
Connection: close
Content-Type: application/json
Date: Thu, 08 Sep 2022 15:19:08 GMT
Date: Thu, 08 Sep 2022 15:19:08 GMT
Host: 127.0.0.1:8000
Set-Cookie: laravel_session=eyJpdiI6InNKVmoza2ZHOXpGamx6cktMV0d1V1E9PSIsInZhbHVlIjoiOGkwY3ZCVTBiRno4d0s2YytkR3pzYzFCeXlqRFk4dC82U0d4NUR4RTJGSHNNVy8rVU9BSCtPUUxmWThtbm1sK3FQdnJQbjhXZDhSUlFkVVlEbndFQk1ML1hNdG9BTkRZblhPaHV6MjdabGVqNTY1TFlyUHJqRU1HZmpXcjg0SUUiLCJtYWMiOiI5YzRlY2Y0ZjFjMmEzZmZmOTJhNTI5MzM0MWI3YTdkMDY5NWIyMGM4MGM5ZGE4NTU5MmNiYTIxODc2ZTQ0NzNkIiwidGFnIjoiIn0%3D; expires=Thu, 08-Sep-2022 17:19:08 GMT; Max-Age=7200; path=/; httponly; samesite=lax
X-Powered-By: PHP/8.1.10

{
    "errors": {
        "email": [
            "The email has already been taken."
        ]
    },
    "message": "The email has already been taken."
}

It's maybe best that you try a support channel if you need further help: