mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-01 03:33:40 -05:00
c6678a2607
* poc: use server session and api key validation on deletion * feat: use server session and api key validation on deletion and creation * feat: packages/lib/apiKey for apiKey services and auth * shubham/auth-for-api-key * fix: caching * feat: handle authorization for action creation, update, delete * feat: handle authorization for survey creation, updation & deletion * feat: use cached method across and wrapper for authzn check * fix: use cached wrapper & introduce more authzn check for survey services in actions * fix: club caching methods and use authzn errors * feat: add caching in canUserAccessApiKey * feat: add caching in canUserAccessAction and use Authzn error * fix: rename action to actionClass wherever needed * feat: use caching in core method and update hasEnvAccess call * fix: use authzn specific error * fix: use cache getActionClass * fix: make changes * fix: import * fix: import and suggested changes * fix: rename action and use cache tag * feat: use services to create team * fix: atomic services for product & team creation * improve teamUpdateInput * use services in signup process * redirect to prod environment when new product is created * fix signup bug --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import ClientLogout from "@/app/ClientLogout";
|
|
import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions";
|
|
import { getFirstEnvironmentByUserId } from "@formbricks/lib/services/environment";
|
|
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}`);
|
|
}
|