Custom Livewire request headers

Custom Livewire request headers

Livewire provides two hooks that you can use to add additional options to the fetch options object. You can add any additional settings that you like, for example, you can set custom headers.

These headers will be applied when Livewire makes requests to the update endpoint (e.g. This might be usefull when building applications or components that have very specific requirements.

1Livewire.hook('request', ({ options }) => {
2 options.headers['Authorization'] = 'Bearer <MY_TOKEN>';

It is also possible to do the same for any requests made when using wire:navigate:

1Livewire.hook('navigate.request', ({ options }) => {
2 options.headers = {
3 'Authorization': 'Bearer <MY_TOKEN>',
4 }
To navigate
Press Enter to select