fix(server): catching possible errors to provide better messages to the client

This commit is contained in:
Miodec 2023-09-04 13:15:41 +02:00
parent babd92d6e2
commit 443a6a59ee

View file

@ -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;
}