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:
|
onlyBuiltDependencies:
|
||||||
- '@prisma/client'
|
- '@prisma/client'
|
||||||
- '@prisma/engines'
|
- '@prisma/engines'
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const EmailFormSchema = z.object({
|
|||||||
smtpHost: z.string(),
|
smtpHost: z.string(),
|
||||||
smtpPort: z.string(),
|
smtpPort: z.string(),
|
||||||
smtpUser: z.string(),
|
smtpUser: z.string(),
|
||||||
|
smtpSecure: z.boolean()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type EmailFormType = z.infer<typeof EmailFormSchema>;
|
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 EmailSettingsTest from "@/components/emails/email-settings-test";
|
||||||
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
|
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
|
||||||
import {Send} from "lucide-react";
|
import {Send} from "lucide-react";
|
||||||
|
import {Switch} from "@/components/ui/switch";
|
||||||
|
|
||||||
export type EmailFormProps = {
|
export type EmailFormProps = {
|
||||||
defaultValues?: EmailFormType;
|
defaultValues?: EmailFormType;
|
||||||
@@ -178,6 +179,23 @@ export const EmailForm = (props: EmailFormProps) => {
|
|||||||
</FormItem>
|
</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">
|
<div className="flex justify-between gap-4">
|
||||||
{props.defaultValues?.smtpFrom && (
|
{props.defaultValues?.smtpFrom && (
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
|
|||||||
+6
-1
@@ -27,7 +27,12 @@ export const env = createEnv({
|
|||||||
SMTP_HOST: z.string().optional(),
|
SMTP_HOST: z.string().optional(),
|
||||||
SMTP_PORT: z.string().optional(),
|
SMTP_PORT: z.string().optional(),
|
||||||
SMTP_USER: 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_ID: z.string().optional(),
|
||||||
AUTH_GOOGLE_SECRET: z.string().optional(),
|
AUTH_GOOGLE_SECRET: z.string().optional(),
|
||||||
|
|||||||
+23
-13
@@ -455,19 +455,29 @@ export const auth = betterAuth({
|
|||||||
|
|
||||||
const deviceInfo = getDeviceDetails(session.userAgent);
|
const deviceInfo = getDeviceDetails(session.userAgent);
|
||||||
|
|
||||||
await sendEmail({
|
|
||||||
to: user.email,
|
try {
|
||||||
subject: "New login to your account",
|
await sendEmail({
|
||||||
html: await render(
|
to: user.email,
|
||||||
EmailNewLogin({
|
subject: "New login to your account",
|
||||||
firstname: user.name!,
|
html: await render(
|
||||||
os: deviceInfo.os,
|
EmailNewLogin({
|
||||||
browser: deviceInfo.browser,
|
firstname: user.name!,
|
||||||
ipAddress: session.ipAddress!,
|
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, {
|
(await auth.$context).internalAdapter.updateUser(user.id, {
|
||||||
lastConnectedAt: new Date(),
|
lastConnectedAt: new Date(),
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ async function setupCronJobs() {
|
|||||||
|
|
||||||
async function createSettingsIfNotExist() {
|
async function createSettingsIfNotExist() {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
|
|
||||||
const systemSettingsValues = {
|
const systemSettingsValues = {
|
||||||
name: "system",
|
name: "system",
|
||||||
smtpPassword: env.SMTP_PASSWORD ?? null,
|
smtpPassword: env.SMTP_PASSWORD ?? null,
|
||||||
|
|||||||
Reference in New Issue
Block a user