My Register Server -Aktion funktioniert auf dem lokalen Host, bricht jedoch beim Bereitstellen für Digitalocean. Ich habe versucht, es im Entwicklungsmodus auf dem Server auszuführen, aber das macht keinen Unterschied.Error in registerUser: [Error: Connection timeout] { code: 'ETIMEDOUT', command: 'CONN' }
< /code>
Hier ist die Serveraktion: < /p>
"use server";
import { actionClient } from "@/lib/safe-action";
import { registerSchema } from "@/schemas/Register-schema";
import { prisma } from "@/prisma";
import bcrypt from "bcryptjs";
import crypto from "crypto";
import { sendSMS } from "@/lib/sms";
import { sendEmail } from "@/lib/email";
export const registerUser = actionClient
.schema(registerSchema)
.action(
async ({
parsedInput: {
forename,
surname,
email,
mobile,
password,
confirmPassword,
role,
},
}) => {
try {
const emailLower = email.toLowerCase();
if (password !== confirmPassword) {
throw new Error("Passwords do not match.");
}
const existingUser = await prisma.user.findFirst({
where: {
email: emailLower,
},
});
if (existingUser) {
return { error: "User already exists" };
}
const salt = bcrypt.genSaltSync(10);
const pwHash = bcrypt.hashSync(password, salt);
const expires = new Date();
expires.setHours(expires.getHours() + 6);
const token = crypto.randomBytes(32).toString("hex");
await prisma.user.create({
data: {
forename,
surname,
email: emailLower,
mobile,
role,
password: pwHash,
},
});
await prisma.emailToken.create({
data: {
token,
expires,
user: {
connect: {
email: emailLower,
},
},
},
});
const mobileToken = (
Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000
).toString();
const mobileExpires = new Date();
mobileExpires.setHours(mobileExpires.getHours() + 6);
await prisma.mobileToken.create({
data: {
token: mobileToken,
expires: mobileExpires,
user: {
connect: {
mobile,
},
},
},
});
await sendEmail(
email,
"welcome@tutacall.com",
"Verify your email",
`Visit ${process.env.BASE_URL}/verify-email?token=${token} to verify your email address.`,
`Verify your email`
);
await sendSMS(
mobile,
"Tutacall",
`Your verification code is: ${mobileToken}. Login and use it within 6 hours.`
);
return { success: "Verification Email and SMS sent!" };
} catch (error) {
console.error("Error in registerUser:", error);
return { error: "An error occurred. Please try again." };
}
}
);
< /code>
Die Datenbank wird aktualisiert, aber es sieht so aus, als würde sie beim Senden der E -Mail fehlschlagen, und ich habe keine Ahnung, warum. Vielleicht werden die Variablen in .env.local nicht geladen, aber NPM laden sie automatisch auf die Clients. Daher sollte dies auf dem Server dieselbe tun, da ich mit NPM auf dem Server teste.>
Warum brechen meine Register -Aktion bei der Bereitstellung? ⇐ JavaScript
-
- Similar Topics
- Replies
- Views
- Last post