diff --git a/packages/data-schemas/src/methods/pluginAuth.ts b/packages/data-schemas/src/methods/pluginAuth.ts index 5355fec50c..9f79552a80 100644 --- a/packages/data-schemas/src/methods/pluginAuth.ts +++ b/packages/data-schemas/src/methods/pluginAuth.ts @@ -10,15 +10,20 @@ import type { // Factory function that takes mongoose instance and returns the methods export function createPluginAuthMethods(mongoose: typeof import('mongoose')) { /** - * Finds a single plugin auth entry by userId and authField + * Finds a single plugin auth entry by userId and authField (and optionally pluginKey) */ async function findOnePluginAuth({ userId, authField, + pluginKey, }: FindPluginAuthParams): Promise { try { const PluginAuth: Model = mongoose.models.PluginAuth; - return await PluginAuth.findOne({ userId, authField }).lean(); + return await PluginAuth.findOne({ + userId, + authField, + ...(pluginKey && { pluginKey }), + }).lean(); } catch (error) { throw new Error( `Failed to find plugin auth: ${error instanceof Error ? error.message : 'Unknown error'}`, diff --git a/packages/data-schemas/src/types/pluginAuth.ts b/packages/data-schemas/src/types/pluginAuth.ts index 421769eaa3..c38bc790ab 100644 --- a/packages/data-schemas/src/types/pluginAuth.ts +++ b/packages/data-schemas/src/types/pluginAuth.ts @@ -18,6 +18,7 @@ export interface PluginAuthQuery { export interface FindPluginAuthParams { userId: string; authField: string; + pluginKey?: string; } export interface FindPluginAuthsByKeysParams {