From 2ee7b10557092b576fa2b4df0a83b19600b53c74 Mon Sep 17 00:00:00 2001 From: Carles Mitjans Date: Sun, 25 Jun 2023 21:16:54 +0200 Subject: [PATCH] feat: get Stripe keys from environment file (#12) --- README.md | 16 +++++++++++----- src/module.ts | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4720104..c1bde05 100644 --- a/README.md +++ b/README.md @@ -83,16 +83,20 @@ export default defineNuxtConfig({ modules: [ 'nuxt3-stripe' ], - stripe: { - apiKey: 'sk_test_123', - publishableKey: 'pk_test_123', - } }) ``` ## Configuration -You can configure the module by providing the necessary Stripe keys and an optional API version in your `nuxt.config.js` file: +Stripe keys can be added to the `.env` file... + +```env +STRIPE_PUBLISHABLE_KEY="pk_live_..." +STRIPE_API_KEY="sk_live_..." +``` + +...or to the Nuxt configuration file: + ```ts export default defineNuxtConfig({ @@ -109,6 +113,8 @@ export default defineNuxtConfig({ }) ``` +> We highly recommend you put your **production** keys in your `.env` file to avoid committing them + ## Development Initial step: Clone this repository diff --git a/src/module.ts b/src/module.ts index d8f3534..19b92a0 100644 --- a/src/module.ts +++ b/src/module.ts @@ -37,8 +37,8 @@ export default defineNuxtModule({ } }, defaults: { - publishableKey: null, - apiKey: null, + publishableKey: process.env.STRIPE_PUBLISHABLE_KEY as string, + apiKey: process.env.STRIPE_API_KEY as string, apiVersion: '2022-11-15' }, setup (options, nuxt) {