Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

chore: Remove unused constant and update lock account logic

Kiran K1f8c2952fb62
diff --git a/apps/web/emails/index.ts b/apps/web/emails/index.ts
index 19f0def350..f888e3c917 100644
--- a/apps/web/emails/index.ts
+++ b/apps/web/emails/index.ts
@@ -23,6 +23,8 @@ export const sendEmail = async ({
react?: ReactElement<any, string | JSXElementConstructor<any>>;
marketing?: boolean;
}) => {
+ return true;
+
if (process.env.NODE_ENV === "development" && !client) {
// Set up a fake email client for development
console.info(
diff --git a/apps/web/lib/auth/constants.ts b/apps/web/lib/auth/constants.ts
index 9218a9c057..f1f3bdeeeb 100644
--- a/apps/web/lib/auth/constants.ts
+++ b/apps/web/lib/auth/constants.ts
@@ -1,5 +1,3 @@
export const PASSWORD_RESET_TOKEN_EXPIRY = 1 * 60 * 60; // 1 hour
-export const ACCOUN_LOCK_DURATION = 24 * 60 * 60; // 24 hours
-
export const MAX_LOGIN_ATTEMPTS = 10;
diff --git a/apps/web/lib/auth/lock-account.ts b/apps/web/lib/auth/lock-account.ts
index f7ee4e3e86..131edc1541 100644
--- a/apps/web/lib/auth/lock-account.ts
+++ b/apps/web/lib/auth/lock-account.ts
@@ -1,11 +1,11 @@
import { prisma } from "@/lib/prisma";
import { User } from "@prisma/client";
-import { ACCOUN_LOCK_DURATION, MAX_LOGIN_ATTEMPTS } from "./constants";
+import { MAX_LOGIN_ATTEMPTS } from "./constants";
export const incrementLoginAttempts = async (
user: Pick<User, "id" | "email">,
) => {
- const { invalidLoginAttempts, lockedUntil } = await prisma.user.update({
+ const { invalidLoginAttempts, lockedAt } = await prisma.user.update({
where: { id: user.id },
data: {
invalidLoginAttempts: {
@@ -13,16 +13,16 @@ export const incrementLoginAttempts = async (
},
},
select: {
- lockedUntil: true,
+ lockedAt: true,
invalidLoginAttempts: true,
},
});
- if (!lockedUntil && invalidLoginAttempts >= MAX_LOGIN_ATTEMPTS) {
+ if (!lockedAt && invalidLoginAttempts >= MAX_LOGIN_ATTEMPTS) {
await prisma.user.update({
where: { id: user.id },
data: {
- lockedUntil: new Date(Date.now() + ACCOUN_LOCK_DURATION * 1000),
+ lockedAt: new Date(),
},
});
@@ -32,7 +32,7 @@ export const incrementLoginAttempts = async (
return {
invalidLoginAttempts,
- lockedUntil,
+ lockedAt,
};
};
@@ -45,17 +45,6 @@ export const resetLoginAttempts = async (userId: string) => {
});
};
-export const isAccountLocked = async (userId: string) => {
- const { lockedUntil } = await prisma.user.findUniqueOrThrow({
- where: { id: userId },
- select: {
- lockedUntil: true,
- },
- });
-
- return lockedUntil && lockedUntil > new Date();
-};
-
export const exceededLoginAttemptsThreshold = (
user: Pick<User, "invalidLoginAttempts">,
) => {
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index 502d5fa02b..54eddc2e34 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -267,6 +267,12 @@ export const authOptions: NextAuthOptions = {
if (!user.email || (await isBlacklistedEmail(user.email))) {
return false;
}
+
+ // @ts-ignore
+ if (user?.lockedAt) {
+ return false;
+ }
+
if (account?.provider === "google" || account?.provider === "github") {
const userExists = await prisma.user.findUnique({
where: { email: user.email },
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 1c48074bf7..2890387afc 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -21,7 +21,7 @@ model User {
isMachine Boolean @default(false)
passwordHash String?
invalidLoginAttempts Int @default(0)
- lockedUntil DateTime?
+ lockedAt DateTime?
accounts Account[]
sessions Session[]