import { NextRequest, NextResponse } from 'next/server'; import { getServerSession } from 'next-auth/next'; import { authOptions } from '@/app/api/auth/[...nextauth]/route'; import { forceRecacheUserCredentials } from '@/lib/services/email-service'; export async function GET(request: NextRequest) { try { // Get session to ensure user is authenticated const session = await getServerSession(authOptions); if (!session || !session.user?.id) { return NextResponse.json( { error: 'Unauthorized' }, { status: 401 } ); } const userId = session.user.id; // Force recache credentials const success = await forceRecacheUserCredentials(userId); if (success) { return NextResponse.json({ success: true, message: 'Credentials recached successfully', userId }); } else { return NextResponse.json( { success: false, error: 'Failed to recache credentials. Check server logs for details.', userId }, { status: 500 } ); } } catch (error) { console.error('Recache API error:', error); return NextResponse.json( { success: false, error: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 } ); } }