'use client';
export function AuthDialog({
open,
onClose,
url,
isError,
error,
step,
isLoading,
signerApprovalUrl,
}: {
open: boolean;
onClose: () => void;
url: string;
isError: boolean;
error?: Error | null;
step: 'signin' | 'access' | 'loading';
isLoading?: boolean;
signerApprovalUrl?: string | null;
}) {
if (!open) return null;
const getStepContent = () => {
switch (step) {
case 'signin':
return {
title: 'Signin',
description:
"To signin, scan the code below with your phone's camera.",
showQR: true,
qrUrl: url,
showOpenButton: true,
};
case 'loading':
return {
title: 'Setting up access...',
description:
'Checking your account permissions and setting up secure access.',
showQR: false,
qrUrl: '',
showOpenButton: false,
};
case 'access':
return {
title: 'Grant Access',
description: (
Allow this app to access your Farcaster account:
Read Access
View your profile and public information
Write Access
Post casts, likes, and update your profile
),
// Show QR code if we have signer approval URL, otherwise show loading
showQR: !!signerApprovalUrl,
qrUrl: signerApprovalUrl || '',
showOpenButton: !!signerApprovalUrl,
};
default:
return {
title: 'Sign in',
description:
"To signin, scan the code below with your phone's camera.",
showQR: true,
qrUrl: url,
showOpenButton: true,
};
}
};
const content = getStepContent();
return (
{isError ? 'Error' : content.title}
{isError ? (
{error?.message || 'Unknown error, please try again.'}
) : (
{typeof content.description === 'string' ? (
{content.description}
) : (
content.description
)}
{content.showQR && content.qrUrl ? (
{/* eslint-disable-next-line @next/next/no-img-element */}
) : step === 'loading' || isLoading ? (
{step === 'loading'
? 'Setting up access...'
: 'Loading...'}
) : null}
{content.showOpenButton && content.qrUrl && (
)}
)}
);
}