mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-24 03:21:20 -05:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 623e82ff4d |
@@ -1,10 +1,13 @@
|
|||||||
import { prisma } from "@formbricks/database";
|
import { prisma } from "@formbricks/database";
|
||||||
import { sendForgotPasswordEmail } from "@formbricks/email";
|
import { sendForgotPasswordEmail } from "@formbricks/email";
|
||||||
|
import { loginLimiter } from "@/app/middleware/bucket";
|
||||||
|
|
||||||
export const POST = async (request: Request) => {
|
export const POST = async (request: Request) => {
|
||||||
const { email } = await request.json();
|
const { email } = await request.json();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await loginLimiter(request.headers.get("x-forwarded-for") || request.connection.remoteAddress);
|
||||||
|
|
||||||
const foundUser = await prisma.user.findUnique({
|
const foundUser = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
email: email.toLowerCase(),
|
email: email.toLowerCase(),
|
||||||
|
|||||||
@@ -29,3 +29,8 @@ export const syncUserIdentificationLimiter = rateLimit({
|
|||||||
interval: SYNC_USER_IDENTIFICATION_RATE_LIMIT.interval,
|
interval: SYNC_USER_IDENTIFICATION_RATE_LIMIT.interval,
|
||||||
allowedPerInterval: SYNC_USER_IDENTIFICATION_RATE_LIMIT.allowedPerInterval,
|
allowedPerInterval: SYNC_USER_IDENTIFICATION_RATE_LIMIT.allowedPerInterval,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const forgotPasswordLimiter = rateLimit({
|
||||||
|
interval: LOGIN_RATE_LIMIT.interval,
|
||||||
|
allowedPerInterval: LOGIN_RATE_LIMIT.allowedPerInterval,
|
||||||
|
});
|
||||||
|
|||||||
@@ -28,3 +28,5 @@ export const isSyncWithUserIdentificationEndpoint = (
|
|||||||
const match = url.match(regex);
|
const match = url.match(regex);
|
||||||
return match ? { environmentId: match[1], userId: match[2] } : false;
|
return match ? { environmentId: match[1], userId: match[2] } : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const forgotPasswordRoute = (url: string) => url === "/api/v1/users/forgot-password";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
shareUrlLimiter,
|
shareUrlLimiter,
|
||||||
signUpLimiter,
|
signUpLimiter,
|
||||||
syncUserIdentificationLimiter,
|
syncUserIdentificationLimiter,
|
||||||
|
forgotPasswordLimiter,
|
||||||
} from "@/app/middleware/bucket";
|
} from "@/app/middleware/bucket";
|
||||||
import {
|
import {
|
||||||
clientSideApiRoute,
|
clientSideApiRoute,
|
||||||
@@ -12,6 +13,7 @@ import {
|
|||||||
loginRoute,
|
loginRoute,
|
||||||
shareUrlRoute,
|
shareUrlRoute,
|
||||||
signupRoute,
|
signupRoute,
|
||||||
|
forgotPasswordRoute,
|
||||||
} from "@/app/middleware/endpointValidator";
|
} from "@/app/middleware/endpointValidator";
|
||||||
import { getToken } from "next-auth/jwt";
|
import { getToken } from "next-auth/jwt";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
@@ -60,6 +62,8 @@ export const middleware = async (request: NextRequest) => {
|
|||||||
}
|
}
|
||||||
} else if (shareUrlRoute(request.nextUrl.pathname)) {
|
} else if (shareUrlRoute(request.nextUrl.pathname)) {
|
||||||
await shareUrlLimiter(`share-${ip}`);
|
await shareUrlLimiter(`share-${ip}`);
|
||||||
|
} else if (forgotPasswordRoute(request.nextUrl.pathname)) {
|
||||||
|
await forgotPasswordLimiter(`forgot-password-${ip}`);
|
||||||
}
|
}
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -83,5 +87,6 @@ export const config = {
|
|||||||
"/api/auth/signout",
|
"/api/auth/signout",
|
||||||
"/auth/login",
|
"/auth/login",
|
||||||
"/api/packages/:path*",
|
"/api/packages/:path*",
|
||||||
|
"/api/v1/users/forgot-password",
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user