Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: redirect to project on user sign in (#541)

Marc Klingen5c5cca0d9e3c
diff --git a/src/components/layouts/layout.tsx b/src/components/layouts/layout.tsx
index a05a520456..f186d85a77 100644
--- a/src/components/layouts/layout.tsx
+++ b/src/components/layouts/layout.tsx
@@ -21,7 +21,8 @@ import { FeedbackButtonWrapper } from "@/src/features/feedback/component/Feedbac
import { Button } from "@/src/components/ui/button";
import Head from "next/head";
import { env } from "@/src/env.mjs";
-import { LangfuseIcon, LangfuseLogo } from "@/src/components/LangfuseLogo";
+import { LangfuseLogo } from "@/src/components/LangfuseLogo";
+import { Spinner } from "@/src/components/layouts/spinner";
const userNavigation = [
{
@@ -531,16 +532,3 @@ export default function Layout(props: PropsWithChildren) {
</>
);
}
-
-function Spinner(props: { message: string }) {
- return (
- <div className="flex min-h-full flex-1 flex-col justify-center py-12 sm:px-6 lg:px-8">
- <div className="sm:mx-auto sm:w-full sm:max-w-md">
- <LangfuseIcon className="mx-auto motion-safe:animate-spin" size={42} />
- <h2 className="mt-5 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
- {props.message} ...
- </h2>
- </div>
- </div>
- );
-}
diff --git a/src/components/layouts/spinner.tsx b/src/components/layouts/spinner.tsx
new file mode 100644
index 0000000000..636d8d0bfd
--- /dev/null
+++ b/src/components/layouts/spinner.tsx
@@ -0,0 +1,14 @@
+import { LangfuseIcon } from "@/src/components/LangfuseLogo";
+
+export function Spinner(props: { message: string }) {
+ return (
+ <div className="flex min-h-full flex-1 flex-col justify-center py-12 sm:px-6 lg:px-8">
+ <div className="sm:mx-auto sm:w-full sm:max-w-md">
+ <LangfuseIcon className="mx-auto motion-safe:animate-spin" size={42} />
+ <h2 className="mt-5 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
+ {props.message} ...
+ </h2>
+ </div>
+ </div>
+ );
+}
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index a21e1c6087..de67b94f15 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -9,40 +9,34 @@ import {
import Link from "next/link";
import { NewProjectButton } from "@/src/features/projects/components/NewProjectButton";
import Header from "@/src/components/layouts/header";
-import { api } from "@/src/utils/api";
import { useRouter } from "next/router";
-import { useState } from "react";
import { env } from "@/src/env.mjs";
import { cn } from "@/src/utils/tailwind";
+import { useSession } from "next-auth/react";
+import { Spinner } from "@/src/components/layouts/spinner";
export default function GetStartedPage() {
const router = useRouter();
- const [loading, setLoading] = useState(true);
const getStarted = router.query.getStarted === "1";
- const projects = api.projects.all.useQuery(undefined, {
- onSuccess: (data) => {
- if (
- data.filter((p) => p.id !== env.NEXT_PUBLIC_DEMO_PROJECT_ID).length &&
- !getStarted
- ) {
- void router.push(
- `/project/${
- data.filter((p) => p.id !== env.NEXT_PUBLIC_DEMO_PROJECT_ID)[0]!.id
- }`,
- );
- setLoading(false);
- } else setLoading(false);
- },
- });
+ const session = useSession();
+ const projects = session.data?.user?.projects;
+ const redirectProject = projects?.filter(
+ (p) => p.id !== env.NEXT_PUBLIC_DEMO_PROJECT_ID,
+ )[0];
- if (loading || projects.status === "loading") {
- return <div>Loading...</div>;
+ if (session.status === "authenticated" && redirectProject && !getStarted) {
+ void router.push(`/project/${redirectProject.id}`);
+ return <Spinner message="Redirecting" />;
+ }
+
+ if (session.status === "loading") {
+ return <Spinner message="Loading" />;
}
const demoProject =
- env.NEXT_PUBLIC_DEMO_PROJECT_ID !== undefined && projects.data?.length
- ? projects.data.find(
+ env.NEXT_PUBLIC_DEMO_PROJECT_ID !== undefined
+ ? projects?.find(
(project) => project.id === env.NEXT_PUBLIC_DEMO_PROJECT_ID,
)
: undefined;