A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
fix: propagate OAuth grant lookup server errors (RX-108)
Amruth Pillai2b24fcd32726
diff --git a/apps/server/src/http/oauth-flow.integration.test.ts b/apps/server/src/http/oauth-flow.integration.test.tsindex 51c258331..01d5e4490 100644--- a/apps/server/src/http/oauth-flow.integration.test.ts+++ b/apps/server/src/http/oauth-flow.integration.test.ts@@ -1,5 +1,6 @@import { createHash, randomBytes } from "node:crypto";import { describe, expect, it, vi } from "vite-plus/test";+import { APIError } from "better-auth";vi.mock("@reactive-resume/email/transport", () => ({ sendEmail: vi.fn() }));@@ -203,6 +204,25 @@ describe.skipIf(!databaseURL)("MCP OAuth flow with PostgreSQL", () => {expect(active.status).toBe(200);await expect(active.json()).resolves.toMatchObject({ active: true });}+ const { db } = await import("@reactive-resume/db/client");+ const schema = await import("@reactive-resume/db/schema");+ const select = db.select.bind(db);+ const lookup = vi.spyOn(db, "select").mockImplementation(() => {+ const query = select();+ const from = query.from.bind(query);+ vi.spyOn(query, "from").mockImplementation((table) => {+ if (table === schema.oauthConsent) throw new APIError("INTERNAL_SERVER_ERROR");+ return from(table);+ });+ return query;+ });+ try {+ expect.soft((await userinfo()).status).toBe(500);+ if (client.client_secret) expect.soft((await introspect()).status).toBe(500);+ } finally {+ lookup.mockRestore();+ }+ expect((await userinfo()).status).toBe(200);const [consent] = await consents();const disconnected = await handleAuth(request("oauth2/delete-consent", { id: consent.id }, cookie));expect(disconnected.status).toBe(200);diff --git a/packages/auth/src/config.ts b/packages/auth/src/config.tsindex 9c43174f4..95bb1969d 100644--- a/packages/auth/src/config.ts+++ b/packages/auth/src/config.ts@@ -791,7 +791,7 @@ const getAuthConfig = () => {await validateOAuthGrant(payload);} catch (error) {// Only a refused grant makes the token inactive; a failed lookup is a server error, not a revocation.- if (!isAPIError(error)) throw error;+ if (!isAPIError(error) || error.statusCode !== 401) throw error;return ctx.json({ active: false });}}),@@ -979,7 +979,7 @@ const getAuthConfig = () => {try {await validateOAuthGrant(jwt);} catch (error) {- if (!isAPIError(error)) throw error;+ if (!isAPIError(error) || error.statusCode !== 401) throw error;throw new APIError("UNAUTHORIZED", {error: "invalid_token",error_description: "Reconnect the application to restore access.",