From e007b9a2be8ed60a179445681ce2f709c4082dac Mon Sep 17 00:00:00 2001 From: jimmy b Date: Mon, 4 Oct 2021 11:16:27 +0200 Subject: [PATCH] Add env var support with dotenv-webpack Set up env for authentication with auth0 add sample env file --- .env.sample | 3 +++ .gitignore | 2 +- package.json | 1 + src/utils/authentication.js | 4 ++-- webpack.config.js | 5 ++++- yarn.lock | 19 +++++++++++++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..24cef33 --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +AUTH_ENABLED=1 +AUTH0_DOMAIN= +AUTH0_CLIENT_ID= diff --git a/.gitignore b/.gitignore index f70a24d..18d132a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.iml out gen - +.env ./node_modules/**/* node_modules/ diff --git a/package.json b/package.json index 1556b29..880bd93 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@babel/preset-env": "^7.14.8", "babel-loader": "^8.2.2", "css-loader": "^6.2.0", + "dotenv-webpack": "^7.0.3", "html-loader": "^2.1.2", "sass": "^1.36.0", "sass-loader": "^12.1.0", diff --git a/src/utils/authentication.js b/src/utils/authentication.js index a3f7d68..25821a9 100644 --- a/src/utils/authentication.js +++ b/src/utils/authentication.js @@ -2,8 +2,8 @@ import router from './router' import { Auth0Client } from '@auth0/auth0-spa-js'; export const auth0 = new Auth0Client({ - domain: '', - client_id: '' + domain: process.env.AUTH0_DOMAIN, + client_id: process.env.AUTH0_CLIENT_ID }); const loginWithAuth = () => { diff --git a/webpack.config.js b/webpack.config.js index b0e7fed..474b2ec 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,10 +1,13 @@ var path = require('path'); +const Dotenv = require('dotenv-webpack'); module.exports = { experiments: { topLevelAwait: true, }, - + plugins: [ + new Dotenv(), + ], devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, diff --git a/yarn.lock b/yarn.lock index 5c6f946..768eed6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1866,6 +1866,25 @@ dot-case@^3.0.4: no-case "^3.0.4" tslib "^2.0.3" +dotenv-defaults@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz#6b3ec2e4319aafb70940abda72d3856770ee77ac" + integrity sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg== + dependencies: + dotenv "^8.2.0" + +dotenv-webpack@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/dotenv-webpack/-/dotenv-webpack-7.0.3.tgz#f50ec3c7083a69ec6076e110566720003b7b107b" + integrity sha512-O0O9pOEwrk+n1zzR3T2uuXRlw64QxHSPeNN1GaiNBloQFNaCUL9V8jxSVz4jlXXFP/CIqK8YecWf8BAvsSgMjw== + dependencies: + dotenv-defaults "^2.0.2" + +dotenv@^8.2.0: + version "8.6.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b" + integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g== + ee-first@1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz"