MCPcopy Create free account
hub / github.com/error311/FileRise / retryWithFreshCsrf

Function retryWithFreshCsrf

public/js/auth.js:167–185  ·  view source on GitHub ↗
(asFormFallback = false)

Source from the content-addressed store, hash-verified

165 }
166
167 async function retryWithFreshCsrf(asFormFallback = false) {
168 const tokRes = await original('/api/auth/token.php', { credentials: 'include' });
169 if (tokRes.ok) {
170 const body = await tokRes.json().catch(() => ({}));
171 if (body?.csrf_token) {
172 window.csrfToken = body.csrf_token;
173 const meta = document.querySelector('meta[name="csrf-token"]');
174 if (meta) meta.content = body.csrf_token;
175 options.headers['X-CSRF-Token'] = body.csrf_token;
176 }
177 }
178 if (asFormFallback && wantJson) {
179 // convert JSON body into x-www-form-urlencoded
180 const orig = options.body && typeof options.body === 'string' ? JSON.parse(options.body) : {};
181 options.body = toFormBody(orig);
182 options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
183 }
184 return original(url, options);
185 }
186
187 let res = await original(url, options);
188

Callers 1

fetchWithCsrfFunction · 0.85

Calls 1

toFormBodyFunction · 0.85

Tested by

no test coverage detected