smartrahat
smartrahat

Reputation: 5609

Laravel logging out automatically

I am using Laravel 5.3 and Laravel's default authentication system. After login the page redirect to the welcome page. But if I click on any other link the page redirect to the login page.

I tried using database for session driver, the result is same.

Upvotes: 1

Views: 763

Answers (1)

smartrahat
smartrahat

Reputation: 5609

Finally I have found the problem. The application is logging out because I used Auth::logout() in blade.

<li>
    <a role="menuitem" tabindex="-1" href="{{ Auth::logout() }}">
        <i class="fa fa-power-off"></i> Logout
    </a>
</li>

In Laravel 5.3 url(/logout) is no longer working. So, I used Auth::logout() but the problem is logout() method on Auth facade is clearing the authentication information from user's session whenever the page load.

Extra:

To get a logout link in application I am using this method:

<li>
    <a href="{{ url('/logout') }}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
        <i class="fa fa-power-off"></i>
        Logout
    </a>
    <form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
        {{ csrf_field() }}
    </form>    
</li>

Upvotes: 1

Related Questions