diff --git a/backend/src/api/controllers/user.ts b/backend/src/api/controllers/user.ts index fda1be35f..3ed967642 100644 --- a/backend/src/api/controllers/user.ts +++ b/backend/src/api/controllers/user.ts @@ -325,14 +325,26 @@ export async function getUser( //if the user is in the auth system but not in the db, its possible that the user was created by bypassing captcha //since there is no data in the database anyway, we can just delete the user from the auth system //and ask them to sign up again - - await FirebaseAdmin().auth().deleteUser(uid); - throw new MonkeyError( - 404, - "User not found in the database, but found in the auth system. We have deleted the ghost user from the auth system. Please sign up again.", - "get user", - uid - ); + try { + await FirebaseAdmin().auth().deleteUser(uid); + throw new MonkeyError( + 404, + "User not found in the database, but found in the auth system. We have deleted the ghost user from the auth system. Please sign up again.", + "get user", + uid + ); + } catch (e) { + if (e.code === "auth/user-not-found") { + throw new MonkeyError( + 404, + "User not found in the database or the auth system. Please sign up again.", + "get user", + uid + ); + } else { + throw e; + } + } } else { throw e; }