Skip to content

Commit

Permalink
Return correct error messages on failed auth attempts (#6593)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Sep 17, 2021
1 parent 273ee44 commit ae691cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-candles-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/auth': patch
---

Fixed bug with incorrect errors being returned on invalid auth attempts.
11 changes: 4 additions & 7 deletions packages/auth/src/lib/findMatchingIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
}
}

0 comments on commit ae691cb

Please sign in to comment.