'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { signIn } from '@/lib/auth-client'; const workosEnabled = process.env['NEXT_PUBLIC_WORKOS_ENABLED'] === 'true'; const keycloakEnabled = process.env['NEXT_PUBLIC_KEYCLOAK_ENABLED'] === 'true'; const hasSsoProviders = workosEnabled || keycloakEnabled; export default function LoginPage(): React.ReactElement { const router = useRouter(); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent): Promise { e.preventDefault(); setError(null); setLoading(true); const form = new FormData(e.currentTarget); const email = form.get('email') as string; const password = form.get('password') as string; const result = await signIn.email({ email, password }); if (result.error) { setError(result.error.message ?? 'Sign in failed'); setLoading(false); return; } router.push('/chat'); } async function handleSsoSignIn(providerId: string): Promise { setError(null); setLoading(true); const result = await signIn.oauth2({ providerId, callbackURL: '/chat' }); if (result?.error) { setError(result.error.message ?? 'SSO sign in failed'); setLoading(false); } } return (

Sign in

Sign in to your Mosaic account

{error && (
{error}
)} {hasSsoProviders && (
{workosEnabled && ( )} {keycloakEnabled && ( )}
or
)}

Don't have an account?{' '} Sign up

); }