import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { useAuthStore } from '../hooks/useAuth' import { useQuery } from '@tanstack/react-query' import api from '../utils/api' export default function LoginPage() { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const authError = new URLSearchParams(window.location.search).get('auth_error') const [error, setError] = useState( authError === 'not_authorized' ? "Your account isn't permitted to access MileVault β ask the admin to add you to the allowed group." : '' ) const { login, isLoading } = useAuthStore() const navigate = useNavigate() const { data: pocketidData } = useQuery({ queryKey: ['pocketid-available'], queryFn: () => api.get('/auth/pocketid/available').then(r => r.data), }) const handleSubmit = async (e) => { e.preventDefault() setError('') try { await login(username, password) navigate('/') } catch (err) { setError(err.response?.data?.detail || 'Login failed') } } const handlePocketID = async () => { const { data } = await api.get('/auth/pocketid/login-url') window.location.href = data.url } return (
Your personal fitness dashboard