Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,415 members, 7,843,235 topics. Date: Tuesday, 28 May 2024 at 09:18 PM

Solution To Tokenmismatchexception Problem In Laravel 5.1 - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Solution To Tokenmismatchexception Problem In Laravel 5.1 (5606 Views)

How To Create Multiple User Authentication In Laravel 5.3 / Common Error In Laravel #1:solved File_put_contents Failed To Open Stream / Create A Nested Lists Of Categories In Laravel 5 (2) (3) (4)

(1) (Reply)

Solution To Tokenmismatchexception Problem In Laravel 5.1 by dplumptre(m): 2:22pm On Sep 14, 2015
Hello peeps , I dont know if you have notice this error "TokenMismatchException in VerifyCsrfToken.php line 53"

sometimes when you are trying to login , it looks alot like the image below



see images below

Laravel provides an easy method of protecting your application from cross-site request forgeries, it uses CSRF Protection

and its can be done by using form helper in your application like this below

{!! Form::open() !!}

{!! Form::close() !!}

From laravel 5 , the form helper has been yanked off , but you can always easily integrate it to your laravel 5.1

application I will cover that in a latter tutorial,

The solution to this error is just navigating to your auth/logout page so it will just destroy the session and login from the

login page again. But if you where designing application for users , you wont want them to see the hideous error page or

even if you have a good error page you still need to find a way to solve the issue for them.

Here is what you do

Create tokenerror_page.blade.php error page that will navigate people to where the will logout from the auth/logout page

the route may look like this below

Route::get('/token_error_page', function () {
return redirect('welcome/tokenerror_page');
});</div>
<strong>the page tokenerror_page.blade.php could contain this</strong>
<div class="well">
<div class="margin-40 score text-center"><i class="fa-5x fa fa-frown-o"></i> well this is embarrassing
<a>Login from here &amp;raquo &amp;raquo</a></div>

see image below


Then you navigate to app/Exceptions/Handler.php

in the render method just include this


if($e instanceof \Illuminate\Session\TokenMismatchException)
{
return redirect('/token_error_page');
}

this will catch the exception and navigate to the error page that you have created and they can click on the login from here button

and this time your users will be able to signin without no errors





if you want to see more stuffs visit my blog http://overallheuristic.com/blog/

site : http://overallheuristic.com
twitter : @dplumptre
fb :https://www.facebook.com/

Re: Solution To Tokenmismatchexception Problem In Laravel 5.1 by dplumptre(m): 9:54am On Oct 12, 2015
if you dont want to create any fancy page , you could just redirect to the logout page


navigate to app/Exceptions/Handler.php

in the render method just include this


if($e instanceof \Illuminate\Session\TokenMismatchException)
{
return redirect('/auth/logout'); //so it kills the session and takes you where you wil login easily
}

(1) (Reply)

Tytit users keep growing since it launched on 7th September / How Long Did It Take You Guys To Become Strong Java Programmers / My Journey Into React Native

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.