Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🐛 Distinguish OTP expiry/attempt errors and instrument verify failures
Luke Vella26107db9a049
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 46678f088..b0dc85af3 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -77,7 +77,7 @@"verificationCodePlaceholder": "Enter your 6-digit code","startOfWeek": "Start of week","weekView": "Week view",- "wrongVerificationCode": "Your verification code is incorrect or has expired",+ "wrongVerificationCode": "Your verification code is incorrect","yes": "Yes","you": "You","yourName": "Your name…",@@ -677,5 +677,7 @@"conferencing": "Conferencing","attendees": "Attendees","invited": "Invited",- "eventOrganizedBy": "Organized by {name}"+ "eventOrganizedBy": "Organized by {name}",+ "expiredVerificationCode": "This code has expired. Request a new one to continue.",+ "tooManyVerificationAttempts": "Too many incorrect attempts. Request a new code to continue."}diff --git a/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsx b/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsxindex 6630b7960..b564c262a 100644--- a/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsx+++ b/apps/web/src/app/[locale]/(auth)/login/verify/components/otp-form.tsx@@ -1,6 +1,7 @@"use client";import { zodResolver } from "@hookform/resolvers/zod";+import { usePostHog } from "@rallly/posthog/client";import { Button } from "@rallly/ui/button";import {Form,@@ -25,6 +26,7 @@ const otpFormSchema = z.object({export function OTPForm({ email }: { email: string }) {const { t } = useTranslation();+ const posthog = usePostHog();const form = useForm({defaultValues: {otp: "",@@ -40,10 +42,33 @@ export function OTPForm({ email }: { email: string }) {});if (res.error) {+ posthog?.capture("login:otp_verify_error", {+ error_code: res.error.code ?? "UNKNOWN",+ status: res.error.status,+ });+switch (res.error.code) {case "INVALID_OTP":form.setError("otp", {- message: t("wrongVerificationCode"),+ message: t("wrongVerificationCode", {+ defaultValue: "Your verification code is incorrect",+ }),+ });+ return;+ case "OTP_EXPIRED":+ form.setError("otp", {+ message: t("expiredVerificationCode", {+ defaultValue:+ "This code has expired. Request a new one to continue.",+ }),+ });+ return;+ case "TOO_MANY_ATTEMPTS":+ form.setError("otp", {+ message: t("tooManyVerificationAttempts", {+ defaultValue:+ "Too many incorrect attempts. Request a new code to continue.",+ }),});return;default:diff --git a/apps/web/tests/authentication.spec.ts b/apps/web/tests/authentication.spec.tsindex 405829e78..cf0996d47 100644--- a/apps/web/tests/authentication.spec.ts+++ b/apps/web/tests/authentication.spec.ts@@ -100,7 +100,7 @@ test.describe.serial(() => {await page.getByPlaceholder("Enter your 6-digit code").fill("000000");await expect(- page.getByText("Your verification code is incorrect or has expired"),+ page.getByText("Your verification code is incorrect"),).toBeVisible();});