0

I am using Auth0 for authentification, and login is working normally, but as soon as I invoke log out function after redirect user is logged again. This is my route file:

<?php

Route::get('/auth0/callback', '\Auth0\Login\Auth0Controller@callback');

Route::group(['middleware' => ['auth']], function () {
    Route::get('/', 'SiteController@index');

    Route::get('/dashboard', 'DashboardController@index')->middleware('role');
    Route::get('/employees-status', 'ReviewStatusPhasesController@employeesStatus')->middleware('role');
    Route::get('/user-status/{id}', 'UserPhaseController@get')->middleware('role');

    Route::get('/request-update/{id}', 'UserController@requestUpdate');

    Route::post('/search', 'UserController@search')->middleware('role');
    Route::post('/change-status', 'UserPhaseController@changeStatus')->middleware('role');

    Route::get('/logout', function() {
        var_dump(Auth::check());
        Auth::logout();
        var_dump(Auth::check());
        die;
        return redirect('login');
    });
});


Route::get('/login', function () {
    return \App::make('auth0')->login();
})->name('login');

It seems that Auth::logout(); is working as it should, because first var_dump is showing true and second is showing false (rest of the setup is same as in docs https://auth0.com/docs/quickstart/webapp/laravel/01-login).

If I try to load the page after logout, I am once again logged in. Any ideas what could be wrong here?

Sasha
  • 8,521
  • 23
  • 91
  • 174

1 Answers1

0

Try to change your route to: Route::get('auth/logout', 'Auth\AuthController@logout'); or try in AuthController constructor add

public function __construct()
{
    $this->middleware('guest', ['except' => ['logout', 'getLogout']]);
}

Taken from: https://stackoverflow.com/a/34667356/1275778 (also check the other answers there if you're still having problems afterwards)

Alvaro Alves
  • 308
  • 1
  • 3
  • 13