Mismatch token error in the Laravel

Asked

Viewed 220 times

0

My login form works correctly:

<form action="{{route('autenticacao.logar')}}" method="post">
    {{csrf_field()}}
    <input type="text" name="cpf" class="form-control" placeholder="CPF" style="border-radius:10px; border-color:blue;" />
    <br/>
    <input type="password" name="senha" class="form-control" placeholder="senha" style="border-radius:10px; border-color:blue;" />
    <br/>
    <input type="submit" class="btn btn-primary btn-block btn-flat" value="Entrar" />
</form>

However, if I log out:

public function logout(){
    Auth::logout();
    Session::flush();

    return view('autenticacao.login');
}

When I try to re-log in, I get error:

Tokenmismatchexception in Verifycsrftoken.php line 68

But if I refresh the page works normally, but it’s annoying for the user to have to refresh the page whenever they want to log in again.

What can it be?

  • 1

    You need to give a redirect in this case, that is, does not load anything in that part, because when logging out and wipes the data of session.

  • @Virgilionovic did not understand well. Because I can not log out since my intention is precisely to clean the data?

  • @Virgilionovic, I managed to solve yes, by doing a search for redirect and logout, thank you

  • 1

    is that in this specific case you had the entire session cleaned and at the same time loaded a view and this does not generate the csrf token, so I said I need to give a redirect to re-generate the data ...

  • 1

    @Virgilionovic got it. solved my problem

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.