1
votes

i used default laravel authentication and get user name into my form. but when i use logout it shows logout route and show error page expire .

this is my view logout code

<ul class="navbar-nav ml-auto">
                    <!-- Authentication Links -->
                    @guest
                            <li><a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a></li>
                    @else
                            <li class="nav-item dropdown">
                                    <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                            {{ Auth::user()->name }} <span class="caret"></span>
                                    </a>

                                    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                            <a class="dropdown-item" href="{{ route('logout') }}"
                                                 onclick="event.preventDefault();
                                                                             document.getElementById('logout-form').submit();">
                                                    {{ __('Logout') }}
                                            </a>

                                            <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                                    @csrf
                                            </form>
                                    </div>
                            </li>
                    @endguest
            </ul>

when i click logout it shows me /logout url and it's not working. how can i fix this error and redirect to my /home path

3
Can you please provide the error you are receiving?CUGreen
page expire error is related to csrf token. I think you should refresh the page and click on logout immediately.Maulik
error page is showing "The page has expired due to inactivity. Please refresh and try again." This is showing localhost/logout routeKalana Mihiranga

3 Answers

1
votes

Just replace @csrf by {{ csrf_field() }} in the logout form:

<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
             {{ csrf_field() }}
 </form>

Your problem because there is no csrf token sent with the logout form.

1
votes

There are possibly issues with your session cookies.

This may depend on your environment but I have fixed the issue before by making sure that config/session.php file contains this line

'domain' => env('SESSION_DOMAIN', null),

Then remove the SESSION_DOMAIN line in your .env file

Then composer dumpautoload

Also, check your APP_URL in your .env is correct.

0
votes

I tried all the above and didnt work but finally did it like this and it worked!!

php artisan ui bootstrap

php artisan ui vue

php artisan ui react


php artisan ui bootstrap --auth

php artisan ui vue --auth

php artisan ui react --auth

Run all this one by one and

npm install
npm run dev

again and it will surely work