diff --git a/.changeset/smooth-candles-crash.md b/.changeset/smooth-candles-crash.md new file mode 100644 index 00000000000..55eb32c7800 --- /dev/null +++ b/.changeset/smooth-candles-crash.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/auth': patch +--- + +Fixed bug with incorrect errors being returned on invalid auth attempts. diff --git a/packages/auth/src/lib/findMatchingIdentity.ts b/packages/auth/src/lib/findMatchingIdentity.ts index 9102adee112..3ce0db4fc66 100644 --- a/packages/auth/src/lib/findMatchingIdentity.ts +++ b/packages/auth/src/lib/findMatchingIdentity.ts @@ -10,13 +10,10 @@ export async function findMatchingIdentity( | { success: false; code: AuthTokenRequestErrorCode } | { success: true; item: { id: any; [prop: string]: any } } > { - try { - const item = await dbItemAPI.findOne({ where: { [identityField]: identity } }); + const item = await dbItemAPI.findOne({ where: { [identityField]: identity } }); + if (item) { return { success: true, item }; - } catch (err: any) { - if (err.message === 'You do not have access to this resource') { - return { success: false, code: 'IDENTITY_NOT_FOUND' }; - } - throw err; + } else { + return { success: false, code: 'IDENTITY_NOT_FOUND' }; } }