Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.7 @csrf is not working after enabling HTTPS

Tags:

php

laravel

Initially my laravel application was working on HTTP protocol, Then I changed the protocol to HTTPS.
Unfortunately now my application's login is not working now.it shows me 419 error, Sorry Your session expired. I tried couple of solutions suggested.
https://laracasts.com/discuss/channels/laravel/post-request-in-laravel-57-error-419-sorry-your-session-has-expired.

Laravel 419 Error - VerifyCsrfToken issue

Post request in Laravel 5.7 --- Error - 419 Sorry, your session has expired.

But none of these solved my issue.

I am using CRUDBOOSTER plugin to manage login.

Routes.php.

/* ROUTER FOR WEB */
Route::group(['middleware' => ['web'], 'prefix' => config('crudbooster.ADMIN_PATH'), 'namespace' => $namespace], function () {

    Route::post('unlock-screen', ['uses' => 'AdminController@postUnlockScreen', 'as' => 'postUnlockScreen']);
    Route::get('lock-screen', ['uses' => 'AdminController@getLockscreen', 'as' => 'getLockScreen']);
    Route::post('forgot', ['uses' => 'AdminController@postForgot', 'as' => 'postForgot']);
    Route::get('forgot', ['uses' => 'AdminController@getForgot', 'as' => 'getForgot']);
    Route::post('register', ['uses' => 'AdminController@postRegister', 'as' => 'postRegister']);
    Route::get('register', ['uses' => 'AdminController@getRegister', 'as' => 'getRegister']);
    Route::get('logout', ['uses' => 'AdminController@getLogout', 'as' => 'getLogout']);
    Route::post('login', ['uses' => 'AdminController@postLogin', 'as' => 'postLogin']);
    Route::get('login', ['uses' => 'AdminController@getLogin', 'as' => 'getLogin']);
});  

My Form

 <form autocomplete='off' action="{{ route('postLogin') }}" method="post">
    @csrf
        <!-- <input type="hidden" name="_token" value="{{ csrf_token() }}"/> -->
        <div class="form-group has-feedback">
            <input autocomplete='off' type="text" class="form-control" name='email' required placeholder="Email"/>
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input autocomplete='off' type="password" class="form-control" name='password' required placeholder="Password"/>
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div style="margin-bottom:10px" class='row'>
            <div class='col-xs-12'>
                <button type="submit" class="btn btn-primary btn-block btn-flat"><i class='fa fa-lock'></i> {{trans("crudbooster.button_sign_in")}}</button>
            </div>
        </div>

        <div class='row'>
            <div class='col-xs-12' align="center"><p style="padding:10px 0px 10px 0px">{{trans("crudbooster.text_forgot_password")}} <a
                            href='{{route("getForgot")}}'>{{trans("crudbooster.click_here")}}</a></p></div>
        </div>
    </form>. 

And I attaching my error screen. Error Screen

can any one help me rid this issue.

like image 259
Mohammed Iqbal Khan Avatar asked Mar 05 '19 16:03

Mohammed Iqbal Khan


1 Answers

If you can see the hidden CSRF HTML input field, clear the cached data:

php artisan cache:clear
php artisan view:clear

and regenerate a new key:

php artisan key:generate
like image 101
mdaka Avatar answered Oct 01 '22 06:10

mdaka