import { Button } from "@/src/components/ui/button"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/src/components/ui/form"; import { Input } from "@/src/components/ui/input"; import { signupSchema } from "@/src/features/auth/lib/signupSchema"; import { zodResolver } from "@hookform/resolvers/zod"; import { signIn } from "next-auth/react"; import Head from "next/head"; import Link from "next/link"; import { useForm } from "react-hook-form"; import type * as z from "zod/v4"; import { env } from "@/src/env.mjs"; import { useState } from "react"; import { LangfuseIcon } from "@/src/components/LangfuseLogo"; import { CloudPrivacyNotice } from "@/src/features/auth/components/AuthCloudPrivacyNotice"; import { CloudRegionSwitch } from "@/src/features/auth/components/AuthCloudRegionSwitch"; import { SSOButtons, useHuggingFaceRedirect, type PageProps, } from "@/src/pages/auth/sign-in"; import { PasswordInput } from "@/src/components/ui/password-input"; import { Divider } from "@tremor/react"; import { Turnstile } from "@marsidev/react-turnstile"; // Use the same getServerSideProps function as src/pages/auth/sign-in.tsx export { getServerSideProps } from "@/src/pages/auth/sign-in"; export default function SignIn({ authProviders, runningOnHuggingFaceSpaces, }: PageProps) { useHuggingFaceRedirect(runningOnHuggingFaceSpaces); const [turnstileToken, setTurnstileToken] = useState(); // Used to refresh turnstile as the token can only be used once const [turnstileCData, setTurnstileCData] = useState( new Date().getTime().toString(), ); const [formError, setFormError] = useState(null); const form = useForm({ resolver: zodResolver(signupSchema), defaultValues: { name: "", email: "", password: "", }, }); async function onSubmit(values: z.infer) { try { setFormError(null); const res = await fetch( `${env.NEXT_PUBLIC_BASE_PATH ?? ""}/api/auth/signup`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(values), }, ); if (!res.ok) { const payload = (await res.json()) as { message: string }; setFormError(payload.message); return; } await signIn<"credentials">("credentials", { email: values.email, password: values.password, callbackUrl: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION && env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== "DEV" ? `${env.NEXT_PUBLIC_BASE_PATH ?? ""}/onboarding` : `${env.NEXT_PUBLIC_BASE_PATH ?? ""}/`, turnstileToken, }); } catch (err) { setFormError("An error occurred. Please try again."); // Refresh turnstile as the token can only be used once if (env.NEXT_PUBLIC_TURNSTILE_SITE_KEY && turnstileToken) { setTurnstileCData(new Date().getTime().toString()); setTurnstileToken(undefined); } } } return ( <> Sign up | Langfuse

Create new account

{env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined ? (
No credit card required.
) : null}
( Name )} /> ( Email )} /> ( Password )} /> {formError ? (
{formError}
) : null} { // Turnstile exists copy-paste also on sign-up.tsx env.NEXT_PUBLIC_TURNSTILE_SITE_KEY !== undefined && ( <> ) }

Already have an account?{" "} Sign in

); }