codalware-auth
Version:
Complete authentication system with enterprise security, attack protection, team workspaces, waitlist, billing, UI components, 2FA, and account recovery - production-ready in 5 minutes. Enhanced CLI with verification, rollback, and App Router scaffolding.
39 lines (30 loc) • 1 kB
text/typescript
import { useState } from 'react';
export function useMagicLink() {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [message, setMessage] = useState<string | null>(null);
const requestMagicLink = async (email: string) => {
setLoading(true);
setError(null);
setMessage(null);
try {
const response = await fetch('/api/auth/magic-link', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'An error occurred');
}
setMessage(data.message);
} catch (err: unknown) {
setError(err instanceof Error ? err.message : 'An error occurred');
} finally {
setLoading(false);
}
};
return { loading, error, message, requestMagicLink };
}