Skip to content

A self-hosted media server and file management system

fix: axios never gets a valid app name to read xsrf tokens with

aminnausin326602308db1
diff --git a/app/Http/Middleware/ValidateCsrfToken.php b/app/Http/Middleware/ValidateCsrfToken.php
index 653bffd5..f1ca45ae 100644
--- a/app/Http/Middleware/ValidateCsrfToken.php
+++ b/app/Http/Middleware/ValidateCsrfToken.php
@@ -73,7 +73,7 @@ class ValidateCsrfToken extends VerifyCsrfToken {
protected function newCookie($request, $config) {
return new Cookie(
// 'XSRF-TOKEN',
- config('app.name', 'MediaServer') . '_XSRF-TOKEN',
+ config('app.name', 'mediaServer') . '_XSRF-TOKEN',
$request->session()->token(),
$this->availableAt(60 * $config['lifetime']),
$config['path'],
@@ -93,6 +93,6 @@ class ValidateCsrfToken extends VerifyCsrfToken {
*/
public static function serialized() {
// Original: return EncryptCookies::serialized('XSRF-TOKEN');
- return EncryptCookies::serialized(config('app.name', 'MediaServer') . '_XSRF-TOKEN');
+ return EncryptCookies::serialized(config('app.name', 'mediaServer') . '_XSRF-TOKEN');
}
}
diff --git a/resources/js/bootstrap.ts b/resources/js/bootstrap.ts
index e3cd194c..ba755224 100644
--- a/resources/js/bootstrap.ts
+++ b/resources/js/bootstrap.ts
@@ -6,10 +6,14 @@
import axios from 'axios';
+const appName = (window as any).APP_NAME || 'mediaServer';
+
window.axios = axios;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
-window.axios.defaults.xsrfCookieName = import.meta.env.VITE_APP_NAME + '_XSRF-TOKEN';
+window.axios.defaults.xsrfCookieName = `${appName}_XSRF-TOKEN`; // this does not work
+window.axios.defaults.xsrfHeaderName = 'X-XSRF-TOKEN';
+window.axios.defaults.withCredentials = true;
/**
* Echo exposes an expressive API for subscribing to channels and listening
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php
index ef86739a..cb96d4e8 100755
--- a/resources/views/layouts/app.blade.php
+++ b/resources/views/layouts/app.blade.php
@@ -24,6 +24,10 @@
window.addEventListener('resize', setVhUnit)
</script>
+ <script>
+ window.APP_NAME = "{{ config('app.name') }}";
+ </script>
+
<link rel="manifest" href="/manifest.json" crossorigin="use-credentials">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>