@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
import { ApprovalStatus } from "@prisma/client";
|
||||
import { recalcShotStatus } from "@/lib/shot-status";
|
||||
import { validateReviewToken } from "@/lib/review-auth";
|
||||
|
||||
async function getOrCreateClientUser(email: string, label?: string | null) {
|
||||
const existing = await db.user.findUnique({ where: { email } });
|
||||
@@ -16,22 +17,19 @@ async function getOrCreateClientUser(email: string, label?: string | null) {
|
||||
});
|
||||
}
|
||||
|
||||
async function validateToken(token: string) {
|
||||
const session = await db.reviewSession.findUnique({ where: { token } });
|
||||
if (!session || !session.isActive) return null;
|
||||
if (session.expiresAt && session.expiresAt < new Date()) return null;
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ token: string }> }
|
||||
) {
|
||||
const { token } = await params;
|
||||
const session = await validateToken(token);
|
||||
if (!session) {
|
||||
const result = await validateReviewToken(token, req);
|
||||
if (result.type === "requiresPassword") {
|
||||
return NextResponse.json({ requiresPassword: true }, { status: 401 });
|
||||
}
|
||||
if (result.type === "invalid") {
|
||||
return NextResponse.json({ error: "Invalid or expired review link" }, { status: 403 });
|
||||
}
|
||||
const session = result.session;
|
||||
|
||||
const body = await req.json();
|
||||
const { versionId, shotId, action, status, notes } = body;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { makeUnlockCookieValue } from "@/lib/review-auth";
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ token: string }> }
|
||||
) {
|
||||
const { token } = await params;
|
||||
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const { password } = body as { password?: string };
|
||||
|
||||
if (!password || typeof password !== "string") {
|
||||
return NextResponse.json({ error: "Password required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const session = await db.reviewSession.findUnique({ where: { token } });
|
||||
if (!session || !session.isActive) {
|
||||
return NextResponse.json({ error: "Invalid or expired review link" }, { status: 403 });
|
||||
}
|
||||
if (session.expiresAt && session.expiresAt < new Date()) {
|
||||
return NextResponse.json({ error: "Invalid or expired review link" }, { status: 403 });
|
||||
}
|
||||
|
||||
if (!session.passwordHash) {
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
|
||||
const valid = await bcrypt.compare(password, session.passwordHash);
|
||||
if (!valid) {
|
||||
return NextResponse.json({ error: "Incorrect password" }, { status: 401 });
|
||||
}
|
||||
|
||||
const cookieName = `rsauth_${token}`;
|
||||
const cookieValue = makeUnlockCookieValue(token);
|
||||
|
||||
const res = NextResponse.json({ success: true });
|
||||
res.cookies.set(cookieName, cookieValue, {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
expires: session.expiresAt,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
});
|
||||
return res;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
import { slackNotifyNewFeedback } from "@/lib/slack";
|
||||
import { validateReviewToken } from "@/lib/review-auth";
|
||||
|
||||
/** Find or create a guest user for the client reviewer based on the session email */
|
||||
async function getOrCreateClientUser(email: string, label?: string | null) {
|
||||
@@ -16,22 +17,19 @@ async function getOrCreateClientUser(email: string, label?: string | null) {
|
||||
});
|
||||
}
|
||||
|
||||
async function validateToken(token: string) {
|
||||
const session = await db.reviewSession.findUnique({ where: { token } });
|
||||
if (!session || !session.isActive) return null;
|
||||
if (session.expiresAt && session.expiresAt < new Date()) return null;
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ token: string }> }
|
||||
) {
|
||||
const { token } = await params;
|
||||
const session = await validateToken(token);
|
||||
if (!session) {
|
||||
const result = await validateReviewToken(token, req);
|
||||
if (result.type === "requiresPassword") {
|
||||
return NextResponse.json({ requiresPassword: true }, { status: 401 });
|
||||
}
|
||||
if (result.type === "invalid") {
|
||||
return NextResponse.json({ error: "Invalid or expired review link" }, { status: 403 });
|
||||
}
|
||||
const session = result.session;
|
||||
|
||||
const body = await req.json();
|
||||
const { versionId, frameNumber, timestamp, text } = body;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
async function validateToken(token: string) {
|
||||
const session = await db.reviewSession.findUnique({ where: { token } });
|
||||
if (!session || !session.isActive) return null;
|
||||
if (session.expiresAt && session.expiresAt < new Date()) return null;
|
||||
return session;
|
||||
}
|
||||
import { validateReviewToken } from "@/lib/review-auth";
|
||||
|
||||
/** GET /api/client/[token]/project — returns project + shots with tasks that have client-visible versions */
|
||||
export async function GET(
|
||||
@@ -14,10 +8,14 @@ export async function GET(
|
||||
{ params }: { params: Promise<{ token: string }> }
|
||||
) {
|
||||
const { token } = await params;
|
||||
const session = await validateToken(token);
|
||||
if (!session) {
|
||||
const result = await validateReviewToken(token, req);
|
||||
if (result.type === "requiresPassword") {
|
||||
return NextResponse.json({ requiresPassword: true }, { status: 401 });
|
||||
}
|
||||
if (result.type === "invalid") {
|
||||
return NextResponse.json({ error: "Invalid or expired review link" }, { status: 403 });
|
||||
}
|
||||
const session = result.session;
|
||||
|
||||
const project = await db.project.findUnique({
|
||||
where: { id: session.projectId },
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
async function validateToken(token: string) {
|
||||
const session = await db.reviewSession.findUnique({ where: { token } });
|
||||
if (!session || !session.isActive) return null;
|
||||
if (session.expiresAt && session.expiresAt < new Date()) return null;
|
||||
return session;
|
||||
}
|
||||
import { validateReviewToken } from "@/lib/review-auth";
|
||||
|
||||
/** GET /api/client/[token]/versions/[versionId] — returns version + comments for client portal */
|
||||
export async function GET(
|
||||
@@ -14,10 +8,14 @@ export async function GET(
|
||||
{ params }: { params: Promise<{ token: string; versionId: string }> }
|
||||
) {
|
||||
const { token, versionId } = await params;
|
||||
const session = await validateToken(token);
|
||||
if (!session) {
|
||||
const result = await validateReviewToken(token, req);
|
||||
if (result.type === "requiresPassword") {
|
||||
return NextResponse.json({ requiresPassword: true }, { status: 401 });
|
||||
}
|
||||
if (result.type === "invalid") {
|
||||
return NextResponse.json({ error: "Invalid or expired review link" }, { status: 403 });
|
||||
}
|
||||
const session = result.session;
|
||||
|
||||
const version = await db.version.findUnique({
|
||||
where: { id: versionId },
|
||||
|
||||
Reference in New Issue
Block a user