Add detailed error messages for missing environment variables

The commit adds detailed error messages for missing environment variables across different configuration files. It updates the zod schema validations in different files, such as feature-flags.config.ts, personal-accounts-server-actions.ts, and others to provide more informative error messages when environment variables are not provided.
This commit is contained in:
giancarlo
2024-04-14 18:50:09 +08:00
parent 81f1bbca3b
commit a549d2d08f
7 changed files with 82 additions and 46 deletions

View File

@@ -1,49 +1,28 @@
import 'server-only';
import { z } from 'zod';
/*
const user = process.env.EMAIL_USER;
const pass = process.env.EMAIL_PASSWORD;
const host = process.env.EMAIL_HOST;
const port = Number(process.env.EMAIL_PORT);
const secure = process.env.EMAIL_TLS !== 'false';
// validate that we have all the required appConfig
if (!user || !pass || !host || !port) {
throw new Error(
`Missing email configuration. Please add the following environment variables:
EMAIL_USER
EMAIL_PASSWORD
EMAIL_HOST
EMAIL_PORT
`,
);
}
return {
host,
port,
secure,
auth: {
user,
pass,
},
};
*/
export const SmtpConfigSchema = z.object({
user: z.string({
description:
'This is the email account to send emails from. This is specific to the email provider.',
required_error: `Please provide the variable EMAIL_USER`,
}),
pass: z.string({
description: 'This is the password for the email account',
required_error: `Please provide the variable EMAIL_PASSWORD`,
}),
host: z.string({
description: 'This is the SMTP host for the email provider',
required_error: `Please provide the variable EMAIL_HOST`,
}),
port: z.number({
description:
'This is the port for the email provider. Normally 587 or 465.',
required_error: `Please provide the variable EMAIL_PORT`,
}),
secure: z.boolean({
description: 'This is whether the connection is secure or not',
required_error: `Please provide the variable EMAIL_TLS`,
}),
secure: z.boolean(),
});