import { Button } from '@affine/admin/components/ui/button'; import { Input } from '@affine/admin/components/ui/input'; import { Label } from '@affine/admin/components/ui/label'; import { FeatureType, getUserFeaturesQuery } from '@affine/graphql'; import { useCallback, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; import { toast } from 'sonner'; import logo from './logo.svg'; export function Auth() { const emailRef = useRef(null); const passwordRef = useRef(null); const navigate = useNavigate(); const login = useCallback(() => { if (!emailRef.current || !passwordRef.current) return; fetch('/api/auth/sign-in', { method: 'POST', body: JSON.stringify({ email: emailRef.current?.value, password: passwordRef.current?.value, }), headers: { 'Content-Type': 'application/json', }, }) .then(() => fetch('/graphql', { method: 'POST', body: JSON.stringify({ operationName: getUserFeaturesQuery.operationName, query: getUserFeaturesQuery.query, variables: {}, }), headers: { 'Content-Type': 'application/json', }, }) ) .then(res => res.json()) .then( ({ data: { currentUser: { features }, }, }) => { if (features.includes(FeatureType.Admin)) { navigate('/admin'); } else { toast.error('You are not an admin'); } } ) .catch(err => { toast.error(`Failed to login: ${err.message}`); }); }, [navigate]); return (

Login

Enter your email below to login to your account

Image
); } export { Auth as Component };