mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-04 12:50:58 -06:00
* format code * fix building issue in database package * update turbo config and package jsons * update error package with more information and license * fix typescript issues in ui package * update package-lock * update packages * clean dependencies in web * clean up dependencies in demo & formbricks-com * remove unsused template file * remove legacy capture endpoint * remove unfinished client endpoints * clean up unused functions * fix formbricks not loading on invalid session * update readme
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import ClientLogout from "@/app/ClientLogout";
|
|
import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions";
|
|
import { WEBAPP_URL } from "@formbricks/lib/constants";
|
|
import type { Session } from "next-auth";
|
|
import { getServerSession } from "next-auth";
|
|
import { headers } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
|
|
async function getEnvironment() {
|
|
const cookie = headers().get("cookie") || "";
|
|
const res = await fetch(`${WEBAPP_URL}/api/v1/environments/find-first`, {
|
|
headers: {
|
|
cookie,
|
|
},
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const error = await res.json();
|
|
console.error(error);
|
|
throw new Error("Failed to fetch data");
|
|
}
|
|
|
|
return res.json();
|
|
}
|
|
|
|
export default async function Home() {
|
|
const session: Session | null = await getServerSession(authOptions);
|
|
|
|
if (!session) {
|
|
redirect("/auth/login");
|
|
}
|
|
|
|
if (session?.user && !session?.user?.onboardingCompleted) {
|
|
return redirect(`/onboarding`);
|
|
}
|
|
|
|
let environment;
|
|
try {
|
|
environment = await getEnvironment();
|
|
} catch (error) {
|
|
console.error("error getting environment", error);
|
|
}
|
|
|
|
if (!environment) {
|
|
console.error("Failed to get first environment of user; signing out");
|
|
return <ClientLogout />;
|
|
}
|
|
|
|
return redirect(`/environments/${environment.id}`);
|
|
}
|