mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
removing user from auth if no data was found in the db
This commit is contained in:
parent
612331ac72
commit
0960d32a1a
|
@ -320,25 +320,17 @@ export async function getUser(
|
|||
userInfo = await UserDAL.getUser(uid, "get user");
|
||||
} catch (e) {
|
||||
if (e.status === 404) {
|
||||
let user;
|
||||
try {
|
||||
user = await FirebaseAdmin().auth().getUser(uid);
|
||||
//exists, recreate in db
|
||||
await UserDAL.addUser(user.displayName, user.email, uid);
|
||||
userInfo = await UserDAL.getUser(uid, "get user (recreated)");
|
||||
} catch (e) {
|
||||
if (e.code === "auth/user-not-found") {
|
||||
//doesnt exist
|
||||
throw new MonkeyError(
|
||||
404,
|
||||
"User not found in the database or authentication system. Please try to sign up again.",
|
||||
"get user",
|
||||
uid
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
//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
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue