1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Laravel 10 - CSRF API request

Discussão em 'Outras Linguagens' iniciado por Matthew, Novembro 1, 2024 às 03:22.

  1. Matthew

    Matthew Guest

    I have this js code on the updated Laravel 5.7 -> Laravel 10. On the old version, this worked perfectly fine, however, here as soon as this js is started, when it is called, it gets damaged and stolen, or what to call it, the CSRF token, when it is no longer possible to use, for example token for logging in or to any form. I don't know how to solve this at all.

    function pollActiveEvent() { var locale = localStorage.getItem('selectedLanguage') || 'default_locale';


    $.ajax({
    url: '/get-active-event-translations',
    type: 'GET',
    data: { locale: locale, _token: '{{ csrf_token() }}' },
    success: function(response) {
    updateActiveEvent(response);
    setTimeout(pollActiveEvent, 5000);
    },
    error: function() {
    console.error("Nepodařilo se provést požadavek na aktivní event.");
    setTimeout(pollActiveEvent, 5000);
    }
    });
    }

    pollActiveEvent();`

    • I tried to delete the CSRF token, grant an exception in the Middleware (VerifyCsrfToken), of course, when the script was turned off, everything ran as it should). As soon as any query is made, during which the page is not refreshed, damage will occur.

    Continue reading...

Compartilhe esta Página