Add auth guards to search and discover API routes

This commit is contained in:
2026-03-03 11:13:14 -05:00
parent f6ee32ca1e
commit d5e985efd9
4 changed files with 22 additions and 2 deletions
+9
View File
@@ -1,9 +1,18 @@
import { headers } from "next/headers";
import { type NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth/server";
import { isTmdbConfigured } from "@/lib/config";
import { discover } from "@/lib/tmdb/client";
import { tmdbImageUrl } from "@/lib/tmdb/image";
export async function GET(req: NextRequest) {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (!isTmdbConfigured()) {
return NextResponse.json(
{
+9
View File
@@ -1,10 +1,19 @@
import { headers } from "next/headers";
import { type NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth/server";
import { isTmdbConfigured } from "@/lib/config";
import { searchMovies, searchMulti, searchTv } from "@/lib/tmdb/client";
import { tmdbImageUrl } from "@/lib/tmdb/image";
import type { TmdbSearchResponse } from "@/lib/tmdb/types";
export async function GET(req: NextRequest) {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (!isTmdbConfigured()) {
return NextResponse.json(
{
+2 -1
View File
@@ -8,8 +8,9 @@ export async function POST(req: NextRequest) {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session)
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const body = await req.json();
const { tmdbId, type } = body;
+2 -1
View File
@@ -8,8 +8,9 @@ export async function POST(req: NextRequest) {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session)
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const body = await req.json();
const { tmdbId, type } = body;