From 9c4fcadc14b0b45aad92632223ce2d519ec5ba72 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Fri, 29 Dec 2023 22:41:34 +0100 Subject: [PATCH] fix: Better error message when not logged in --- src/app/[lang]/dashboard/bulk/page.tsx | 8 +++++++- src/app/api/v1/bulk/[jobId]/download/route.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/[lang]/dashboard/bulk/page.tsx b/src/app/[lang]/dashboard/bulk/page.tsx index e414abe..dd4df50 100644 --- a/src/app/[lang]/dashboard/bulk/page.tsx +++ b/src/app/[lang]/dashboard/bulk/page.tsx @@ -1,19 +1,25 @@ import React from "react"; import { Dashboard } from "../Dashboard"; import { ENABLE_BULK } from "@/util/helpers"; -import { getSubscription } from "@/supabase/supabaseServer"; +import { getSession, getSubscription } from "@/supabase/supabaseServer"; import { dictionary } from "@/dictionaries"; import { cookies } from "next/headers"; import { createClient } from "@/supabase/server"; import { Csv } from "./Csv"; import { Spacer } from "@/components/Geist"; import { BulkHistory } from "./BulkHistory"; +import { redirect } from "next/navigation"; export default async function Bulk({ params: { lang }, }: { params: { lang: string }; }) { + const session = await getSession(); + if (!session) { + return redirect(`/${lang}/login`); + } + const subscription = await getSubscription(); const d = await dictionary(lang); diff --git a/src/app/api/v1/bulk/[jobId]/download/route.ts b/src/app/api/v1/bulk/[jobId]/download/route.ts index 5590ad7..23e204b 100644 --- a/src/app/api/v1/bulk/[jobId]/download/route.ts +++ b/src/app/api/v1/bulk/[jobId]/download/route.ts @@ -47,6 +47,17 @@ export const GET = async ( ); } + if (!res.data.length) { + return Response.json( + { + error: "No results found", + }, + { + status: 404, + } + ); + } + const rows = res.data.map((row) => { const result = row.result as CheckEmailOutput; result.misc;