mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: smtp crash due to SMTP_SECURE (#246)
Co-authored-by: charles-gauthereau <charles.gauthereau@soluce-technologies.com>
This commit is contained in:
co-authored by
charles-gauthereau
parent
e02c5496ae
commit
27e1da6363
@@ -1,3 +1,5 @@
|
||||
ignoredBuiltDependencies:
|
||||
- node-pty
|
||||
onlyBuiltDependencies:
|
||||
- '@prisma/client'
|
||||
- '@prisma/engines'
|
||||
|
||||
@@ -6,6 +6,7 @@ export const EmailFormSchema = z.object({
|
||||
smtpHost: z.string(),
|
||||
smtpPort: z.string(),
|
||||
smtpUser: z.string(),
|
||||
smtpSecure: z.boolean()
|
||||
});
|
||||
|
||||
export type EmailFormType = z.infer<typeof EmailFormSchema>;
|
||||
|
||||
@@ -30,6 +30,7 @@ import {render} from "@react-email/components";
|
||||
import EmailSettingsTest from "@/components/emails/email-settings-test";
|
||||
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
|
||||
import {Send} from "lucide-react";
|
||||
import {Switch} from "@/components/ui/switch";
|
||||
|
||||
export type EmailFormProps = {
|
||||
defaultValues?: EmailFormType;
|
||||
@@ -178,6 +179,23 @@ export const EmailForm = (props: EmailFormProps) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="smtpSecure"
|
||||
render={({field}) => (
|
||||
<FormItem>
|
||||
<FormLabel>Secure</FormLabel>
|
||||
<FormControl>
|
||||
<Switch
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage/>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="flex justify-between gap-4">
|
||||
{props.defaultValues?.smtpFrom && (
|
||||
<Tooltip>
|
||||
|
||||
+6
-1
@@ -27,7 +27,12 @@ export const env = createEnv({
|
||||
SMTP_HOST: z.string().optional(),
|
||||
SMTP_PORT: z.string().optional(),
|
||||
SMTP_USER: z.string().optional(),
|
||||
SMTP_SECURE: z.coerce.boolean().default(true),
|
||||
|
||||
|
||||
SMTP_SECURE: z
|
||||
.enum(["true", "false"])
|
||||
.transform((val) => val === "true")
|
||||
.default("true"),
|
||||
|
||||
AUTH_GOOGLE_ID: z.string().optional(),
|
||||
AUTH_GOOGLE_SECRET: z.string().optional(),
|
||||
|
||||
+23
-13
@@ -455,19 +455,29 @@ export const auth = betterAuth({
|
||||
|
||||
const deviceInfo = getDeviceDetails(session.userAgent);
|
||||
|
||||
await sendEmail({
|
||||
to: user.email,
|
||||
subject: "New login to your account",
|
||||
html: await render(
|
||||
EmailNewLogin({
|
||||
firstname: user.name!,
|
||||
os: deviceInfo.os,
|
||||
browser: deviceInfo.browser,
|
||||
ipAddress: session.ipAddress!,
|
||||
}),
|
||||
{},
|
||||
),
|
||||
});
|
||||
|
||||
try {
|
||||
await sendEmail({
|
||||
to: user.email,
|
||||
subject: "New login to your account",
|
||||
html: await render(
|
||||
EmailNewLogin({
|
||||
firstname: user.name!,
|
||||
os: deviceInfo.os,
|
||||
browser: deviceInfo.browser,
|
||||
ipAddress: session.ipAddress!,
|
||||
}),
|
||||
{},
|
||||
),
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("sendEmail failed", {
|
||||
userId: user.id,
|
||||
details: "Please Check your env variables or system config",
|
||||
email: user.email,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
(await auth.$context).internalAdapter.updateUser(user.id, {
|
||||
lastConnectedAt: new Date(),
|
||||
|
||||
@@ -48,6 +48,7 @@ async function setupCronJobs() {
|
||||
|
||||
async function createSettingsIfNotExist() {
|
||||
await db.transaction(async (tx) => {
|
||||
|
||||
const systemSettingsValues = {
|
||||
name: "system",
|
||||
smtpPassword: env.SMTP_PASSWORD ?? null,
|
||||
|
||||
Reference in New Issue
Block a user