mercredi 8 juin 2016

How to resolve TokenMismatchException in Laravel 5 App

I have developed a laravel 5 app and everything works fine except that I occationally get TokenMismatchException in VerifyCsrfToken.php line 53. I can't seem to figure out the cause. This happens mostly during login. I used the laravel built-in trait to implement authentication. Below is my sample logout method.

public function getLogout()
    {
        Auth::logout();
        Session::forget('cart_id');
        Session::forget('is_supervisor');
        Session::forget('is_manager');
        return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
    }

Each time the exception occurs, I have to reload the page and login again before this works. Below is a sample of my login form:

{!! Form::open(array('class' => 'form-horizontal', 'role' => 'form')) !!}
     <div class="form-group">
         {!! Form::label('username', trans('home.username'), array('class' => 'col-sm-3 control-label')) !!}
             <div class="col-sm-9 col-lg-5">
                {!! Form::text('username', null, array('required' => 'required', 'class' => 'form-control input-sm')) !!}
                        </div>
          </div>
{!! Form::close() !!}

When I check the page source, the csrf token is always available. What could possibly be the problem. I am using laravel 5.1.*



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire