Skip to content

Commit

Permalink
feat: use runtimeConfig to set options (#250)
Browse files Browse the repository at this point in the history
Nuxt allows you to use environment variables through useRuntimeConfig. This is preferable when you
want different settings in different environments, and want to use secrets (e.g. SMTP username and
password) without exposing them in nuxt.config.ts. This change adds `runtimeConfig.mail` options to
the options object.

fix #120
  • Loading branch information
chrismarsh-hhl authored Sep 27, 2024
1 parent 46f7ed2 commit 524b715
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ const moduleName = parsePackagejsonName(packageConfig.name).fullName;

export default function (moduleOptions, nuxt) {
nuxt = nuxt || this;
const options = { ...nuxt.options.mail, ...moduleOptions };

Check failure on line 25 in src/index.js

View workflow job for this annotation

GitHub Actions / test (18, ubuntu-latest)

'useRuntimeConfig' is not defined

Check failure on line 25 in src/index.js

View workflow job for this annotation

GitHub Actions / test (20, ubuntu-latest)

'useRuntimeConfig' is not defined
const runtimeConfig = useRuntimeConfig();

const options = {
...runtimeConfig.mail,
...nuxt.options.mail,
...moduleOptions,
};

if (!options.smtp) {
throw new Error('SMTP config is missing.');
Expand Down

0 comments on commit 524b715

Please sign in to comment.