mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-20 19:30:41 -05:00
29 lines
734 B
TypeScript
29 lines
734 B
TypeScript
"use client";
|
|
|
|
import { fetcher } from "@formbricks/lib/fetcher";
|
|
import { signOut } from "next-auth/react";
|
|
import { redirect } from "next/navigation";
|
|
import { useEffect } from "react";
|
|
import useSWR from "swr";
|
|
|
|
export function HomeRedirect() {
|
|
const { data, error } = useSWR(`/api/v1/environments/find-first`, fetcher);
|
|
|
|
useEffect(() => {
|
|
if (data && !error) {
|
|
return redirect(`/environments/${data.id}`);
|
|
} else if (error) {
|
|
console.error(error);
|
|
}
|
|
}, [data, error]);
|
|
|
|
if (error) {
|
|
setTimeout(() => {
|
|
signOut();
|
|
}, 3000);
|
|
return <div>There was an error with your current Session. You are getting redirected to the login.</div>;
|
|
}
|
|
|
|
return <div>Loading environment...</div>;
|
|
}
|