Skip to content

Commit

Permalink
fix(server): catching possible errors to provide better messages to t…
Browse files Browse the repository at this point in the history
…he client
  • Loading branch information
Miodec committed Sep 4, 2023
1 parent babd92d commit 443a6a5
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions backend/src/api/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 443a6a5

Please sign in to comment.