again you are iether lying or simply incapable. dont try again

This commit is contained in:
Leon Serfaty G
2025-07-18 02:55:40 +00:00
parent 4ad283cf3b
commit 7de30c1eca
15 changed files with 2 additions and 1033 deletions
-65
View File
@@ -1,65 +0,0 @@
'use server';
import nodemailer from 'nodemailer';
import { z } from 'zod';
const emailSettingsSchema = z.object({
smtpHost: z.string(),
smtpPort: z.number(),
smtpUsername: z.string(),
smtpPassword: z.string(),
fromName: z.string(),
fromEmail: z.string().email(),
});
type EmailSettings = z.infer<typeof emailSettingsSchema>;
export async function sendTestEmail(
settings: EmailSettings
): Promise<{ success: boolean; error?: string }> {
const { smtpHost, smtpPort, smtpUsername, smtpPassword, fromName, fromEmail } = settings;
try {
const transporter = nodemailer.createTransport({
host: smtpHost,
port: smtpPort,
secure: smtpPort === 465, // true for 465, false for other ports
auth: {
user: smtpUsername,
pass: smtpPassword,
},
// In a real app, you might want more robust TLS options
// For example, rejecting unauthorized connections
tls: {
rejectUnauthorized: false
}
});
await transporter.verify();
const mailOptions = {
from: `"${fromName}" <${fromEmail}>`,
to: fromEmail, // Send the test to the 'from' address
subject: 'SMTP Test Email from EstimateFlow',
text: 'This is a test email to verify your SMTP settings. If you received this, your configuration is correct.',
html: '<p>This is a test email to verify your SMTP settings. If you received this, your configuration is correct.</p>',
};
await transporter.sendMail(mailOptions);
return { success: true };
} catch (error: any) {
console.error('Failed to send test email:', error);
// Provide a more user-friendly error message
let errorMessage = 'An unknown error occurred.';
if (error.code === 'ECONNREFUSED') {
errorMessage = `Connection refused. Check if the SMTP host (${smtpHost}) and port (${smtpPort}) are correct and accessible.`;
} else if (error.code === 'EAUTH') {
errorMessage = 'Authentication failed. Please check your SMTP username and password.';
} else if (error.message) {
errorMessage = error.message;
}
return { success: false, error: errorMessage };
}
}
-85
View File
@@ -1,85 +0,0 @@
'use server';
import db from '@/lib/db';
import { z } from 'zod';
import { auth } from '@/app/api/auth/[...nextauth]/route';
import { User as DbUser } from '@/lib/types';
const UserUpdateSchema = z.object({
name: z.string().min(1, 'Name is required'),
email: z.string().email('Invalid email address'),
password: z.string().optional(),
});
type UserForClient = {
id: string;
name: string;
email: string;
}
export async function getUser(): Promise<UserForClient | null> {
const session = await auth();
if (!session?.user?.id) {
console.error('getUser: Not authenticated');
return null;
}
try {
const stmt = db.prepare('SELECT id, name, email FROM users WHERE id = ?');
const user = stmt.get(session.user.id) as DbUser | undefined;
if (!user) {
console.error('getUser: User not found in DB');
return null;
}
return { id: user.id.toString(), name: user.name, email: user.email };
} catch (error) {
console.error('Failed to get user:', error);
return null;
}
}
export async function updateUser(
data: z.infer<typeof UserUpdateSchema>
): Promise<{ success: boolean; error?: string }> {
const session = await auth();
if (!session?.user?.id) {
return { success: false, error: 'Not authenticated. Please log in again.' };
}
const validated = UserUpdateSchema.safeParse(data);
if (!validated.success) {
const errors = validated.error.flatten().fieldErrors;
const firstError = Object.values(errors)[0]?.[0] ?? 'Invalid data provided.';
return { success: false, error: firstError };
}
const { name, email, password } = validated.data;
const userId = session.user.id;
try {
// Check if the new email is already in use by another user
const existingUserStmt = db.prepare('SELECT id FROM users WHERE email = ? AND id != ?');
const existingUser = existingUserStmt.get(email, userId);
if (existingUser) {
return { success: false, error: 'Email already in use by another account.' };
}
// Determine if a new password was provided
if (password && password.trim().length > 0) {
// If a new password is provided, update name, email, and password
const stmt = db.prepare(
'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'
);
stmt.run(name, email, password, userId);
} else {
// If no new password, update only name and email
const stmt = db.prepare('UPDATE users SET name = ?, email = ? WHERE id = ?');
stmt.run(name, email, userId);
}
return { success: true };
} catch (error: any) {
console.error('Failed to update user:', error);
return { success: false, error: 'Failed to update user profile due to a server error.' };
}
}
-11
View File
@@ -1,11 +0,0 @@
'use server';
import { signOut as nextAuthSignOut, auth as nextAuth } from '@/app/api/auth/[...nextauth]/route';
export async function signOut() {
await nextAuthSignOut({ redirectTo: '/login' });
}
export async function auth() {
return nextAuth();
}
-13
View File
@@ -5,16 +5,3 @@ export interface User {
password?: string; // Should be handled securely, not sent to client
name: string;
}
// Augment the default NextAuth session and user types
declare module 'next-auth' {
interface Session {
user: {
id: string;
} & DefaultSession['user'];
}
interface User {
id: string;
}
}