My-Weekly-ToDo-List/src/app/api/reminders/verify/route.ts
mARTin 798bcfe44a feat: Add Google Tasks, Apple Reminders, task import/sync, holidays, and UI enhancements
- Add Google Tasks integration and Apple Reminders support
- Add task import/export with list management APIs
- Add goal API for weekly goals
- Add German holidays library
- Add ImportListModal component
- Enhance WeeklyView with major UI improvements
- Enhance CalendarSettings with new connection options
- Add external task fields to database schema
- Add Playwright test suites for auth and tasks
- Add iCloud reminders Python scripts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 16:56:14 +01:00

83 lines
2.6 KiB
TypeScript

import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
import { PrismaClient } from '@prisma/client';
import { submitSecurityCode } from '@/lib/apple-reminders';
const prisma = new PrismaClient();
export async function POST(req: Request) {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.email) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const body = await req.json();
const { email, code, password } = body;
if (!email || !code || !password) {
return NextResponse.json(
{ error: 'Email, security code, and password are required' },
{ status: 400 }
);
}
console.log('[REMINDERS VERIFY] Submitting 2FA code for:', email);
const result = await submitSecurityCode(email, code, password);
if (!result.success) {
return NextResponse.json(
{ error: result.error || 'Invalid security code' },
{ status: 400 }
);
}
console.log('[REMINDERS VERIFY] 2FA verification successful');
const user = await prisma.user.findUnique({
where: { email: session.user.email }
});
if (!user) {
return NextResponse.json({ error: 'User not found' }, { status: 404 });
}
// Save connection as apple-reminders provider
const accessToken = `${email}:${password}`;
const existingConnection = await prisma.calendarConnection.findFirst({
where: { userId: user.id, provider: 'apple-reminders' }
});
if (existingConnection) {
await prisma.calendarConnection.update({
where: { id: existingConnection.id },
data: { accessToken, updatedAt: new Date() }
});
} else {
await prisma.calendarConnection.create({
data: {
userId: user.id,
provider: 'apple-reminders',
accessToken,
calendars: []
}
});
}
return NextResponse.json({
success: true,
message: 'Apple Reminders verified and connected successfully!'
});
} catch (error: any) {
console.error('[REMINDERS VERIFY] Error:', error);
return NextResponse.json(
{ error: error.message || 'Verification failed' },
{ status: 500 }
);
}
}