Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🚸 Reject banned users before sending a login verification code (#2639)
Luke Vella31cc2d2a1a94
diff --git a/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx b/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsxindex 09035ce38..4cf263fbb 100644--- a/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx+++ b/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx@@ -74,6 +74,14 @@ export function LoginWithEmailForm() {}),});break;+ case "BANNED_USER":+ form.setError("identifier", {+ message: t("authErrorsUserBanned", {+ defaultValue:+ "This account has been banned. Please contact support if you believe this is an error.",+ }),+ });+ break;default:form.setError("password", {message: res.error.message,@@ -111,6 +119,14 @@ export function LoginWithEmailForm() {message: t("authErrorsEmailBlocked"),});break;+ case "BANNED_USER":+ form.setError("identifier", {+ message: t("authErrorsUserBanned", {+ defaultValue:+ "This account has been banned. Please contact support if you believe this is an error.",+ }),+ });+ break;default:form.setError("identifier", {message: res.error.message,diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.tsindex 356477e79..6c7241fb6 100644--- a/apps/web/src/lib/auth.ts+++ b/apps/web/src/lib/auth.ts@@ -311,6 +311,25 @@ export const authLib = betterAuth({});}}++ // Reject banned users before a verification code goes out — the+ // admin plugin only enforces bans at session creation, which is+ // after the OTP email has already been sent. Keyed off `email`+ // only: the change-email endpoints submit `newEmail` and already+ // require a session, which a banned user cannot hold.+ const accountEmail = ctx.body?.email as string | undefined;+ if (accountEmail) {+ const user = await prisma.user.findUnique({+ where: { email: accountEmail },+ select: { banned: true },+ });+ if (user?.banned) {+ throw new APIError("FORBIDDEN", {+ code: "BANNED_USER",+ message: "You have been banned from this application",+ });+ }+ }}}),after: createAuthMiddleware(async (ctx) => {