calcom/cal.diy · error · Error
No valid authentication method found
Error message
No valid authentication method found
What it means
Branching auth logic in the `CloseComCRMService` constructor: after parsing, it tries API-key auth via `parsedKey.data.encrypted`, then OAuth via `parsedKey.data.access_token`; if neither is present it throws this Error. The credential passed schema validation but contains no usable auth method.
Source
Thrown at packages/app-store/closecom/lib/CrmService.ts:92
);
}
// Initialize CloseCom client based on credential type
if (parsedKey.data.encrypted) {
// API key authentication
const decrypted = symmetricDecrypt(parsedKey.data.encrypted, CALENDSO_ENCRYPTION_KEY);
const { api_key } = JSON.parse(decrypted);
this.closeCom = new CloseCom(api_key);
} else if (parsedKey.data.access_token) {
// OAuth authentication
this.closeCom = new CloseCom(parsedKey.data.access_token, {
refresh_token: parsedKey.data.refresh_token,
expires_at: parsedKey.data.expires_at,
isOAuth: true,
userId: credential.userId!,
});
} else {
throw new Error("No valid authentication method found");
}
}
closeComUpdateCustomActivity = async (uid: string, event: CalendarEvent) => {
const customActivityTypeInstanceData = await getCustomActivityTypeInstanceData(
event,
calComCustomActivityFields,
this.closeCom
);
// Create Custom Activity type instance
const customActivityTypeInstance = await this.closeCom.activity.custom.create(
customActivityTypeInstanceData
);
return this.closeCom.activity.custom.update(uid, customActivityTypeInstance);
};
closeComDeleteCustomActivity = async (uid: string) => {
return this.closeCom.activity.custom.delete(uid);View on GitHub (pinned to 176037d0af)
Solutions
- Have the user reconnect Close.com so the credential stores either a valid `encrypted` API key or a full OAuth token set.
- Tighten `credentialSchema` to require at least one auth method (use `z.union(...)` or `.refine()`) so this state is rejected at parse time with a clearer error.
- Audit where empty credentials can be persisted (failed OAuth save path) and add a guard there.
- Log the credential `id`/`userId` when this throws so support can find the offending row.
Example fix
// before
const parsedKey = credentialSchema.safeParse(credential.key);
if (!parsedKey.success) { /* ... */ }
// ... later
} else {
throw new Error("No valid authentication method found");
}
// after
const parsedKey = credentialSchema
.refine((k) => Boolean(k.encrypted) || Boolean(k.access_token), {
message: "No valid authentication method found",
})
.safeParse(credential.key);
if (!parsedKey.success) {
throw new Error(
`Invalid credentials for userId ${credential.userId} and appId ${credential.appId}: ${parsedKey.error}`
);
} Defensive patterns
Strategy: validation
Validate before calling
const parsed = credentialSchema
.refine((k) => Boolean(k.encrypted) || Boolean(k.access_token), { message: "No auth method" })
.safeParse(credential.key);
if (!parsed.success) throw new Error(`Credential unusable: ${parsed.error}`); Type guard
function hasCloseAuthMethod(k: unknown): boolean {
return !!k && typeof k === "object" && (Boolean((k as any).encrypted) || Boolean((k as any).access_token));
} Try / catch
try {
new CloseComCRMService(credential);
} catch (e) {
if (e instanceof Error && /No valid authentication method/.test(e.message)) {
await promptUserReconnect(credential.userId, "closecom");
return null;
}
throw e;
} Prevention
- Make the schema require at least one auth method via refine/union.
- Block empty credential persistence at the OAuth save boundary.
- Add a credential-health job that flags rows with no auth method.
- Log credential id (not key) when this throws to locate the bad row.
When it happens
Trigger: Credential `key` satisfies the zod schema (both `encrypted` and `access_token` are optional) but contains neither — e.g. a credential saved as an empty/partial object, or a future credential type that the constructor doesn't yet handle.
Common situations: Credential row written with placeholder/empty values during a failed setup; schema allows `{}` but no auth fields populated; race between credential creation and token persistence.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Invalid credentials for userId ${credential.userId} and appI
- `code` must be a string
- ${appSlug} not connected.
- Trying to reschedule an event-type which requires authentica
- Cal.diy: Invalid BTCPay credentials
AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12).
Data as JSON: /api/errors/cf930887bee33baa.
Report an issue: GitHub.