Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/api/export/resume/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ import { authOptions } from "@/lib/auth";
import prisma from "@/lib/prisma";
import { renderToBuffer } from "@react-pdf/renderer";
import { generateResumePDF } from "@/lib/generateResumePDF";
import { checkRateLimit } from "@/lib/rateLimit";

export async function GET() {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.email) {
return new Response("Unauthorized", { status: 401 });
}

const allowed = await checkRateLimit(
`export-resume:${session.user.email}`,
2,
60 * 1000
);

if (!allowed) {
return new Response("Too many requests. Please slow down.", { status: 429 });
}
const user = await prisma.user.findUnique({
where: { email: session.user.email },
include: { links: true },
Expand Down
11 changes: 11 additions & 0 deletions app/api/export/vcard/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getServerSession } from "next-auth";
import { authOptions } from "@/lib/auth";
import prisma from "@/lib/prisma";
import { buildVCard } from "@/lib/buildVCard";
import { checkRateLimit } from "@/lib/rateLimit";

export async function GET() {
try {
Expand All @@ -10,6 +11,16 @@ export async function GET() {
return new Response("Unauthorized", { status: 401 });
}

const allowed = await checkRateLimit(
`export-vcard:${session.user.email}`,
10,
60 * 1000
);

if (!allowed) {
return new Response("Too many requests. Please slow down.", { status: 429 });
}

const user = await prisma.user.findUnique({
where: { email: session.user.email },
include: { links: true },
Expand Down
14 changes: 14 additions & 0 deletions app/api/user/delete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import prisma from "@/lib/prisma";
import bcrypt from "bcryptjs";
import { verifyOtp, clearOtp } from "@/lib/deleteOtpStore";
import { invalidateUserSessions } from "@/lib/sessionInvalidation";
import { checkRateLimit } from "@/lib/rateLimit";

export async function DELETE(req: NextRequest) {
try {
Expand All @@ -14,6 +15,19 @@ export async function DELETE(req: NextRequest) {
}

const userId = session.user.id;

const allowed = await checkRateLimit(
`delete-account:${userId}`,
5,
15 * 60 * 1000
);

if (!allowed) {
return NextResponse.json(
{ error: "Too many attempts. Please try again later." },
{ status: 429 }
);
}
let body: unknown;
try {
body = await req.json();
Expand Down
6 changes: 6 additions & 0 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const authOptions: NextAuthOptions = {
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
allowDangerousEmailAccountLinking: true,
}),
]
: []),
Expand All @@ -50,6 +51,7 @@ export const authOptions: NextAuthOptions = {
GitHub({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
allowDangerousEmailAccountLinking: true,
}),
]
: []),
Expand All @@ -70,6 +72,10 @@ export const authOptions: NextAuthOptions = {

if (!user || !user.password) return null;

if (!user.emailVerified) {
throw new Error("Please verify your email address to log in.");
}

const isValid = await bcrypt.compare(
credentials.password,
user.password
Expand Down
6 changes: 2 additions & 4 deletions lib/profileWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,8 @@ export async function publishProfileDraft(
// Handle username change - create alias for old username
if (beforeSnapshot.username && beforeSnapshot.username !== afterSnapshot.username) {
// Recheck availability within the transaction to guard against TOCTOU races
const takenByOther = await tx.user.findFirst({
where: { username: afterSnapshot.username, NOT: { id: userId } },
});
if (takenByOther) {
const isAvailable = await isProfileUsernameAvailable(afterSnapshot.username, userId, tx);
if (!isAvailable) {
throw new Error("Username already taken");
}
await ensureUsernameAliases(tx, userId, beforeSnapshot.username);
Expand Down
Loading