import { type FormEvent, useEffect, useState } from 'react'; import { Navigate } from 'react-router'; import { useAuthStore } from './auth-store'; import { api } from '../api/client'; import { Card, Input, Button, Alert, FormField } from '@cameleer/design-system'; import styles from './LoginPage.module.css'; interface OidcInfo { clientId: string; authorizationEndpoint: string; } export function LoginPage() { const { isAuthenticated, login, loading, error } = useAuthStore(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [oidc, setOidc] = useState(null); const [oidcLoading, setOidcLoading] = useState(false); useEffect(() => { api.GET('/auth/oidc/config') .then(({ data }) => { if (data?.authorizationEndpoint && data?.clientId) { setOidc({ clientId: data.clientId, authorizationEndpoint: data.authorizationEndpoint }); if (data.endSessionEndpoint) { localStorage.setItem('cameleer-oidc-end-session', data.endSessionEndpoint); } } }) .catch(() => {}); }, []); if (isAuthenticated) return ; const handleSubmit = (e: FormEvent) => { e.preventDefault(); login(username, password); }; const handleOidcLogin = () => { if (!oidc) return; setOidcLoading(true); const redirectUri = `${window.location.origin}/oidc/callback`; const params = new URLSearchParams({ response_type: 'code', client_id: oidc.clientId, redirect_uri: redirectUri, scope: 'openid email profile', }); window.location.href = `${oidc.authorizationEndpoint}?${params}`; }; return (
cameleer3

Sign in to access the observability dashboard

{error && (
{error}
)} {oidc && ( <>
or
)}
setUsername(e.target.value)} placeholder="Enter your username" autoFocus autoComplete="username" disabled={loading} /> setPassword(e.target.value)} placeholder="••••••••" autoComplete="current-password" disabled={loading} />
); }