Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(auth): claim device code before approve/deny (better-auth 1.6.11)

Andrejd57a9574d68f
diff --git a/apps/web/src/routes/device/approve.tsx b/apps/web/src/routes/device/approve.tsx
index ca9f095bc..37ab1f01a 100644
--- a/apps/web/src/routes/device/approve.tsx
+++ b/apps/web/src/routes/device/approve.tsx
@@ -94,6 +94,9 @@ function DeviceApprovePage() {
const handleApprove = async () => {
setProcessing(true);
try {
+ // better-auth >= 1.6.11 requires the signed-in user to claim the code
+ // (GET /device) before it can be approved. No-op if already claimed.
+ await authClient.device({ query: { user_code: normalizedCode } });
const res = await authClient.device.approve({
userCode: normalizedCode,
});
@@ -113,6 +116,9 @@ function DeviceApprovePage() {
const handleDeny = async () => {
setProcessing(true);
try {
+ // Claim the code first (see handleApprove) so deny is authorized in
+ // better-auth >= 1.6.11.
+ await authClient.device({ query: { user_code: normalizedCode } });
const res = await authClient.device.deny({
userCode: normalizedCode,
});
diff --git a/tests/api-integration/device-authorization.test.ts b/tests/api-integration/device-authorization.test.ts
index 8077d2a5e..f4c7af472 100644
--- a/tests/api-integration/device-authorization.test.ts
+++ b/tests/api-integration/device-authorization.test.ts
@@ -190,6 +190,20 @@ describe("API integration: device authorization (RFC 8628)", () => {
interval: number;
};
+ // better-auth >= 1.6.11 requires the authenticated user to first claim the
+ // code (GET /device?user_code=...) before it can be approved.
+ const claimRes = await app.request(
+ `/api/auth/device?user_code=${encodeURIComponent(devicePayload.user_code)}`,
+ {
+ method: "GET",
+ headers: {
+ Origin: origin,
+ Cookie: cookieJar,
+ },
+ },
+ );
+ expect(claimRes.status).toBe(200);
+
const approveRes = await app.request("/api/auth/device/approve", {
method: "POST",
headers: {