Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Fellipe's avatar

Login stopped working

hello, I'm having trouble establishing a session, before it worked.

I was having problems with 'CSRF mismatch', I fixed it by doing

public function handle($request, \Closure $next) {
        if (
            $this->isReading($request) ||
            $this->runningUnitTests() ||
            $this->shouldAddXsrfTokenCookie() ||
            $this->tokensMatch($request)
        ) {
            return $this->addCookieToResponse($request, $next($request));
        }
}

but now it won't establish session, it just stopped working

my routes:

Route::prefix('user')->group(function () {
    Route::controller(LoginController::class)->group(function () { /* Controller Login */
        Route::middleware('guest')->group(function () {
            Route::get('/login', 'index')->name('login.index');
            Route::post('/login', 'doLogin')->name('login.doLogin');
        });
        Route::middleware('auth')->group(function () {
            Route::get('/logout', 'doLogout')->name('login.doLogout');
        });
    });

    Route::controller(ProfileController::class)->group(function () { /* Controller Profile */
        Route::get('/profile/{name}.{id}', 'search')->name('profile.search');
        Route::middleware(['auth'])->group(function () {
            Route::get('/profile', 'profile')->name('profile.index');
            Route::get('/friends', 'friends')->name('profile.friends');
            Route::get('/votes', 'votes')->name('profile.votes');
            Route::get('/citys', 'citys')->name('profile.citys');
        });
    });

    Route::controller(RegisterController::class)->group(function () { /* Controller Register*/
        Route::middleware('guest')->group(function () {
            Route::get('/register', 'index')->name('register.index');
            Route::post('/register', 'doRegister')->name('register.create');
        });
    });
});

login function:

    public function doLogin(Request $request){
        if (Auth::attempt([
            'name' => $request->get('name'),
            'password' => $request->get('password'),
            'deleted_at' => NULL
        ])) {
            $request->session()->regenerate();
            return response()->json([
                'status' => 'success',
                'message' => 'Logged!'
            ]);
        }

        return response()->json([
            'status' => 'error',
            'message' => 'Not found user!'
        ], 400);
    }

session unit:

SESSION_DRIVER=file
php artisan route:clear
php artisan cache:clear
php artisan view:clear
0 likes
1 reply
vincent15000's avatar

Which framework are you using to write your front ?

Can you give complete information ?

Please or to participate in this conversation.