Neah version mail forward fix 6

This commit is contained in:
alma 2025-04-16 20:17:34 +02:00
parent ce51819070
commit cdc26d0ada
4 changed files with 135 additions and 7 deletions

7
.env.local Normal file
View File

@ -0,0 +1,7 @@
# SMTP Configuration
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-specific-password
SMTP_FROM=your-email@gmail.com

View File

@ -1,24 +1,59 @@
import { NextResponse } from 'next/server';
import { createTransport } from 'nodemailer';
import { cookies } from 'next/headers';
interface StoredCredentials {
email: string;
password: string;
host: string;
port: number;
}
function getStoredCredentials(): StoredCredentials | null {
const cookieStore = cookies();
const credentialsCookie = cookieStore.get('imap_credentials');
if (!credentialsCookie?.value) {
return null;
}
try {
const credentials = JSON.parse(credentialsCookie.value);
if (!credentials.email || !credentials.password || !credentials.host || !credentials.port) {
return null;
}
return credentials;
} catch (error) {
return null;
}
}
export async function POST(request: Request) {
try {
const credentials = getStoredCredentials();
if (!credentials) {
return NextResponse.json(
{ error: 'No stored credentials found' },
{ status: 401 }
);
}
const { to, cc, bcc, subject, body, attachments } = await request.json();
// Create a transporter using SMTP
// Create a transporter using SMTP with the same credentials
const transporter = createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: process.env.SMTP_SECURE === 'true',
host: credentials.host,
port: credentials.port,
secure: true, // Use TLS
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
user: credentials.email,
pass: credentials.password,
},
});
// Prepare email options
const mailOptions = {
from: process.env.SMTP_FROM || process.env.SMTP_USER,
from: credentials.email,
to,
cc,
bcc,

74
lib/auth.ts Normal file
View File

@ -0,0 +1,74 @@
import { NextAuthOptions } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
declare module 'next-auth' {
interface User {
id: string;
email: string;
password: string;
}
interface Session {
user: User;
}
}
export const authOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
email: { label: 'Email', type: 'email' },
password: { label: 'Password', type: 'password' }
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
return null;
}
// Find user in database
const user = await prisma.user.findUnique({
where: { email: credentials.email },
});
if (!user) {
return null;
}
// Here you would typically verify the password
// For now, we'll just return the user
return {
id: user.id,
email: user.email,
password: user.password,
};
}
})
],
session: {
strategy: 'jwt',
},
pages: {
signIn: '/login',
},
callbacks: {
async jwt({ token, user }) {
if (user) {
token.id = user.id;
token.email = user.email;
token.password = user.password;
}
return token;
},
async session({ session, token }) {
if (token) {
session.user.id = token.id as string;
session.user.email = token.email as string;
session.user.password = token.password as string;
}
return session;
}
}
};

View File

@ -11,6 +11,16 @@ datasource db {
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
email String @unique
password String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
calendars Calendar[]
events Event[]
}
model Calendar {
id String @id @default(uuid())
name String
@ -20,6 +30,7 @@ model Calendar {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
events Event[]
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
}
@ -37,6 +48,7 @@ model Event {
userId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([calendarId])
@@index([userId])