Files
formbricks/apps/web/app/page.tsx
T
Rotimi Best de40dc36e6 chore: move all services into the new folder structure (#948)
* chore: move environment services

* chore: move all services
2023-10-04 18:04:38 +02:00

36 lines
1.0 KiB
TypeScript

import ClientLogout from "@/app/ClientLogout";
import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions";
import { getFirstEnvironmentByUserId } from "@formbricks/lib/environment/service";
import type { Session } from "next-auth";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
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 getFirstEnvironmentByUserId(session?.user.id);
if (!environment) {
throw new Error("No environment found");
}
} 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}`);
}