(request: NextRequest)
| 38 | const eligibility = await checkEmailSignInEligibility(email, request); |
| 39 | if (!eligibility.ok) { |
| 40 | return NextResponse.json(eligibility.body, { status: eligibility.status }); |
| 41 | } |
| 42 | |
| 43 | const magicLink = await createMagicLinkToken(email); |
| 44 | const result = await sendMagicLinkEmail(magicLink, callbackUrl); |
| 45 | |
| 46 | if (!result.sent) { |
| 47 | if (result.reason === 'neverbounce_rejected') { |
| 48 | return NextResponse.json( |
| 49 | { |
| 50 | success: false, |
| 51 | error: 'Unable to deliver email to this address. Please use a different email.', |
| 52 | }, |
| 53 | { status: 400 } |
| 54 | ); |
| 55 | } |
| 56 | // provider_not_configured — internal issue, don't blame the user's email |
| 57 | return NextResponse.json( |
| 58 | { success: false, error: 'An internal error occurred. Please try again later.' }, |
| 59 | { status: 500 } |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | return NextResponse.json({ |
| 64 | success: true, |
| 65 | message: 'Magic link sent to your email', |
| 66 | }); |
| 67 | } |
no test coverage detected