diff --git a/ClipCascade_Mobile/src/App.js b/ClipCascade_Mobile/src/App.js index 72aec4ba9..ec792d6a4 100644 --- a/ClipCascade_Mobile/src/App.js +++ b/ClipCascade_Mobile/src/App.js @@ -100,7 +100,11 @@ export default function App() { try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), timeout_ms); - return await fetch(input, { ...init, signal: controller.signal }); + return await fetch(input, { + credentials: 'include', + ...init, + signal: controller.signal, + }); } catch (e) { throw e; } @@ -467,31 +471,24 @@ export default function App() { return [false, 'No CSRF token found in login page', data_s]; } - // 2. Retrieve the cookie(s) from the "Set-Cookie" header - const setCookieHeader = loginPageResponse.headers.get('set-cookie'); - if (!setCookieHeader) { - return [false, 'No Set-Cookie header returned from login page', null]; - } - - // 3. Prepare form data with the credentials AND the CSRF token + // 2. Prepare form data with the credentials AND the CSRF token const formData = new URLSearchParams(); formData.append('username', data_s.username); formData.append('password', password_s); formData.append('_csrf', csrfToken); - // 4. Send a POST request to the login URL with cookies + form data + // 3. Send a POST request with the cookie retained by the native cookie jar const loginResponse = await fetchTimeout(data_s.server_url + LOGIN_URL, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', - Cookie: setCookieHeader, // Include the cookies from the initial GET }, body: formData.toString(), }); const loginResponseText = await loginResponse.text(); - // 5. Check for login success + // 4. Check for login success if ( loginResponse.ok && !loginResponseText.toLowerCase().includes('bad credentials') @@ -646,7 +643,7 @@ export default function App() { setLoginStatusMessage(''); // clear cookies if any - NativeBridgeModule.clearCookies(); + await NativeBridgeModule.clearCookies(); } catch (error) { if (error.name === 'AbortError') { setWsPageMessage('❌ Error: Request timed out'); diff --git a/ClipCascade_Mobile/src/android/app/src/main/java/com/clipcascade/NativeBridgeModule.kt b/ClipCascade_Mobile/src/android/app/src/main/java/com/clipcascade/NativeBridgeModule.kt index 954f4dac4..1ad24baae 100644 --- a/ClipCascade_Mobile/src/android/app/src/main/java/com/clipcascade/NativeBridgeModule.kt +++ b/ClipCascade_Mobile/src/android/app/src/main/java/com/clipcascade/NativeBridgeModule.kt @@ -38,9 +38,10 @@ class NativeBridgeModule(reactContext: ReactApplicationContext) : ReactContextBa fun clearCookies(promise: Promise) { try { val cookieManager = CookieManager.getInstance() - cookieManager.removeAllCookies(null) - cookieManager.flush() - promise.resolve("Cookies cleared successfully!") + cookieManager.removeAllCookies { + cookieManager.flush() + promise.resolve("Cookies cleared successfully!") + } } catch (e: Exception) { promise.reject("COOKIE_ERROR", "Failed to clear cookies", e) }