Skip to content

Commit b3047a4

Browse files
MarkusPayneMark Payne
andauthored
Update token handling in Livewire requests (#286)
The token handling code for Livewire requests in token_handler.blade.php was refactored. Instead of using the addHeaders method, the code now uses a hook to directly add the auth token and other headers into the request options. Co-authored-by: Mark Payne <[email protected]>
1 parent dc36fc5 commit b3047a4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/resources/views/partials/token_handler.blade.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
window.jQuery.ajaxSettings.headers = { 'Authorization': bearer };
3232
}
3333
}
34-
35-
if (window.Livewire) {
36-
// livewire
37-
window.livewire.addHeaders({
38-
'Authorization': bearer,
39-
'content-type': 'application/json',
40-
'X-Requested-With': 'XMLHttpRequest'
34+
35+
if (window.Livewire) {
36+
window.Livewire.hook('request', ({options}) => {
37+
options.headers['Authorization'] = `Bearer ${window.sessionToken}`;
38+
options.headers['Content-Type'] = 'application/json';
39+
options.headers['X-Requested-With'] = 'XMLHttpRequest';
4140
});
4241
}
4342

0 commit comments

Comments
 (0)