Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 3f89cdd

Browse files
authored
Merge pull request #314 from plotly/use-env-var-for-auth-frontend
Use env var for auth frontend
2 parents b5aaa30 + 01ae736 commit 3f89cdd

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ RUN yarn run heroku-postbuild
5252

5353
ENV PLOTLY_CONNECTOR_PORT 9494
5454
EXPOSE 9494
55-
ENTRYPOINT yarn run start-headless
55+
ENTRYPOINT yarn run build-web && yarn run start-headless

app/components/Configuration.react.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class Configuration extends Component {
1414
this.state = {
1515
isMenuOpen: false,
1616
username: cookie.load('db-connector-user'),
17-
authDisabled: cookie.load('db-connector-auth-disabled')
17+
/* global PLOTLY_ENV */
18+
authDisabled: !PLOTLY_ENV.AUTH_ENABLED
1819
};
1920
this.toggle = this.toggle.bind(this);
2021
this.close = this.close.bind(this);

app/components/Login.react.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ class Login extends Component {
126126
}
127127
buildOauthUrl() {
128128
const {domain} = this.state;
129-
const oauthClientId = 'isFcew9naom2f1khSiMeAtzuOvHXHuLwhPsM7oPt';
129+
/* global PLOTLY_ENV */
130+
const oauthClientId = PLOTLY_ENV.OAUTH2_CLIENT_ID;
130131

131132
const redirect_uri = baseUrlWrapped;
132133
return (

backend/routes.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,6 @@ export default class Servers {
200200
Logger.log(`Listening at: ${protocol}://${domain}:${port}`);
201201
server.listen(port);
202202

203-
// Set AUTH_ENABLED into a cookie so that frontend can show login-modal accordingly:
204-
server.use((req, res, next) => {
205-
const authEnabled = getSetting('AUTH_ENABLED');
206-
if (!authEnabled || that.isElectron) {
207-
res.setCookie('db-connector-auth-disabled', true);
208-
}
209-
210-
next();
211-
});
212-
213203
server.get(/\/static\/?.*/, restify.serveStatic({
214204
directory: `${__dirname}/../`
215205
}));

webpack.config.web.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import webpack from 'webpack';
22
import baseConfig from './webpack.config.base';
33
import path from 'path';
44

5+
const AUTH_ENABLED = process.env.PLOTLY_CONNECTOR_AUTH_ENABLED ?
6+
JSON.parse(process.env.PLOTLY_CONNECTOR_AUTH_ENABLED) : true;
7+
8+
const OAUTH2_CLIENT_ID = process.env.PLOTLY_CONNECTOR_OAUTH2_CLIENT_ID ?
9+
JSON.stringify(process.env.PLOTLY_CONNECTOR_OAUTH2_CLIENT_ID) :
10+
JSON.stringify('isFcew9naom2f1khSiMeAtzuOvHXHuLwhPsM7oPt');
11+
512
const config = {
613
...baseConfig,
714

@@ -23,6 +30,16 @@ const config = {
2330
new webpack.DefinePlugin({
2431
__DEV__: false,
2532
'process.env.NODE_ENV': JSON.stringify('production')
33+
}),
34+
35+
// This is used to pass environment variables to frontend
36+
// detailed discussions on this ticket:
37+
// https://github.com/plotly/streambed/issues/10436
38+
new webpack.DefinePlugin({
39+
'PLOTLY_ENV': {
40+
'AUTH_ENABLED': AUTH_ENABLED,
41+
'OAUTH2_CLIENT_ID': OAUTH2_CLIENT_ID
42+
}
2643
})
2744
],
2845

0 commit comments

Comments
 (0)