38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { getServerSession } from 'next-auth';
|
|
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
|
import { getUserEmailCredentials } from '@/lib/services/email-service';
|
|
|
|
export async function GET() {
|
|
try {
|
|
// Authenticate user
|
|
const session = await getServerSession(authOptions);
|
|
if (!session || !session.user?.id) {
|
|
return NextResponse.json(
|
|
{ error: "Not authenticated" },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
// Get user's email credentials
|
|
const credentials = await getUserEmailCredentials(session.user.id);
|
|
|
|
if (!credentials) {
|
|
return NextResponse.json(
|
|
{ error: "No email credentials found" },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
// Return the email address
|
|
return NextResponse.json({
|
|
email: credentials.email
|
|
});
|
|
} catch (error: any) {
|
|
console.error("Error fetching user email:", error);
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch user email", message: error.message },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|