Laravel 5.4 TokenMismatchException in VerifyCsrfToken.php line 68

后端 未结 4 1212
走了就别回头了
走了就别回头了 2020-12-18 11:07

When I login for the first time it works perfectly but when I log out from my app and try to re-login I get this error.

I\'ve tried almost every available solutions

相关标签:
4条回答
  • 2020-12-18 11:23

    Is your button to disconnect in a form? If so, you need to put this: {{ csrf_field }} in your form of type POST.

    0 讨论(0)
  • 2020-12-18 11:40

    Maybe the form has not declared the input tag of the token:

    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    
    0 讨论(0)
  • 2020-12-18 11:46

    Go to config/session file and check if you have this line below:

    'domain' => env('SESSION_DOMAIN', null)
    

    If yes, then visit your .env file and also set like this:

    SESSION_DOMAIN=null
    

    Then refresh, should be fine.

    0 讨论(0)
  • 2020-12-18 11:50

    You error may be coming from your session manipulation. When you do

    Auth::attempt($data)
    

    The user is already set in the session. You don't need to do your Session::put() thingy. To get the user, do

    $user = Auth::user();
    

    To logout, you do

    Auth::logout(); //will clear the user from the session automatically
    

    So to summarise, remove all the session manipulations you have in your code. Only play with Auth;

    Session::flush(); //DELETE THIS LINE
    

    Add Auth to the top of your controller with

    use Auth; //easier to work like that. 
    
    0 讨论(0)
提交回复
热议问题