🪻 distributed transcription service thistle.dunkirk.sh

bug: fix session self kill failure thnks to @mpkendall

dunkirk.sh 9deff468 20300ab9

verified
Changed files
+42 -1
src
+2 -1
src/components/user-settings.ts
···
});
if (!response.ok) {
-
this.error = "Failed to kill session";
+
const data = await response.json();
+
this.error = data.error || "Failed to kill session";
return;
}
+32
src/index.test.ts
···
expect(response.status).toBe(404);
});
+
+
serverTest("should not delete current session", async () => {
+
// Register user
+
const hashedPassword = await clientHashPassword(
+
TEST_USER.email,
+
TEST_USER.password,
+
);
+
const registerResponse = await fetch(`${BASE_URL}/api/auth/register`, {
+
method: "POST",
+
headers: { "Content-Type": "application/json" },
+
body: JSON.stringify({
+
email: TEST_USER.email,
+
password: hashedPassword,
+
}),
+
});
+
const sessionCookie = extractSessionCookie(registerResponse);
+
+
// Try to delete own current session
+
const response = await authRequest(
+
`${BASE_URL}/api/sessions`,
+
sessionCookie,
+
{
+
method: "DELETE",
+
headers: { "Content-Type": "application/json" },
+
body: JSON.stringify({ sessionId: sessionCookie }),
+
},
+
);
+
+
expect(response.status).toBe(400);
+
const data = await response.json();
+
expect(data.error).toContain("Cannot kill current session");
+
});
});
});
+8
src/index.ts
···
user_agent: s.user_agent,
created_at: s.created_at,
expires_at: s.expires_at,
+
is_current: s.id === sessionId,
})),
});
},
···
if (!targetSessionId) {
return Response.json(
{ error: "Session ID required" },
+
{ status: 400 },
+
);
+
}
+
// Prevent deleting current session
+
if (targetSessionId === currentSessionId) {
+
return Response.json(
+
{ error: "Cannot kill current session. Use logout instead." },
{ status: 400 },
);
}