added catch, disabled cache for send verification email

This commit is contained in:
Miodec 2023-04-11 23:24:14 +02:00
parent 588e7efed8
commit f29db00949
2 changed files with 16 additions and 2 deletions

View file

@ -63,7 +63,19 @@ export async function sendVerificationEmail(
req: MonkeyTypes.Request
): Promise<MonkeyResponse> {
const { email, uid } = req.ctx.decodedToken;
const isVerified = (await admin.auth().getUser(uid)).emailVerified;
const isVerified = (
await admin
.auth()
.getUser("uid")
.catch((e) => {
throw new MonkeyError(
500, // this should never happen, but it does. it mightve been caused by auth token cache, will see if disabling cache fixes it
"Auth user not found, even though the token got decoded",
JSON.stringify({ uid, email, stack: e.stack }),
uid
);
})
).emailVerified;
if (isVerified === true) {
throw new MonkeyError(400, "Email already verified");
}

View file

@ -593,7 +593,9 @@ router.post(
router.get(
"/verificationEmail",
authenticateRequest(),
authenticateRequest({
noCache: true,
}),
RateLimit.userRequestVerificationEmail,
asyncHandler(UserController.sendVerificationEmail)
);