import { type FormEvent, useEffect, useState } from 'react'; import { Navigate } from 'react-router'; import { useAuthStore } from './auth-store'; import { config } from '../config'; 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(() => { fetch(`${config.apiBaseUrl}/auth/oidc/config`) .then((res) => (res.ok ? res.json() : null)) .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
{oidc && ( <>
or
)}
setUsername(e.target.value)} autoFocus autoComplete="username" />
setPassword(e.target.value)} autoComplete="current-password" />
{error &&
{error}
}
); }