Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions ClipCascade_Mobile/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down