Skip to content

Commit

Permalink
Add env var support with dotenv-webpack
Browse files Browse the repository at this point in the history
Set up env for authentication with auth0
add sample env file
  • Loading branch information
James-Burgess committed Oct 4, 2021
1 parent dec1d3e commit e007b9a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AUTH_ENABLED=1
AUTH0_DOMAIN=
AUTH0_CLIENT_ID=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.iml
out
gen

.env

./node_modules/**/*
node_modules/
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import router from './router'
import { Auth0Client } from '@auth0/auth0-spa-js';

export const auth0 = new Auth0Client({
domain: '<auth0 domain>',
client_id: '<auth0 client id>'
domain: process.env.AUTH0_DOMAIN,
client_id: process.env.AUTH0_CLIENT_ID
});

const loginWithAuth = () => {
Expand Down
5 changes: 4 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

[email protected]:
version "1.1.1"
resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz"
Expand Down

0 comments on commit e007b9a

Please sign in to comment.