#CSRF token mismatch

1 messages · Page 1 of 1 (latest)

trim folio
#

#rules:

Please do not take screenshots of code, instead, use triple backticks around your code when pasting into discord

fluid finch
#

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
delicate gulch
#

Why are you messing with the default csrf stuff

#

Also could you stop creating a new thread to a somewhat identical problem, to what you had before? It's still open and I've been awaiting your response

trim folio
#

@fluid finch Can you keep stuff to one thread, please.

delicate gulch
#

It seems to me you should debug your entire Sanctum setup

fluid finch