Skip to content

Commit

Permalink
added env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Subhang23 committed Jun 20, 2020
1 parent 8622acf commit dcd7531
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ REDIS_HOST=
REDIS_PORT=
# WHITELIST DOMAINS (separated by commas, no space)
WHITELISTED_DOMAINS=http://localhost:3000,http://localhost:3080
# SENTRY CONFIG
SENTRY_DSN=<dsn value for the sentry backend project>
REACT_APP_SENTRY_DSN=<dsn value for the sentry frontend project>

# AUTH0 CREDENTIALS
REACT_APP_AUTH0_DOMAIN=<username>.auth0.com
REACT_APP_AUTH0_CLIENT_ID=<Get from auth0>
REACT_APP_AUTH0_CALLBACK_URL=http://localhost:3000/callback
REACT_APP_AUTH0_TOKEN_ENDPOINT=https://<username>.auth0.com/oauth/token
REACT_APP_AUTH0_API_ENDPOINT=https://<username>.auth0.com/api/v2/users
REACT_APP_AUTH0_API_ENDPOINT=https://<username>.auth0.com/api/v2/users
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const cors = require('cors');

const Sentry = require('@sentry/node');

Sentry.init({ dsn: '' });
Sentry.init({ dsn: `${process.env.SENTRY_DSN}` });

// database setup
const mongoose = require('mongoose');
Expand Down
8 changes: 2 additions & 6 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ function onError(error) {
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(`${bind} requires elevated privileges`);
throw new Error(`${bind} requires elevated privileges`);
Logger.error(`${bind} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.error(`${bind} is already in use`);
throw new Error(`${bind} is already in use`);
Logger.error(`${bind} is already in use`);
process.exit(1);
break;
default:
throw error;
}
Expand Down
19 changes: 9 additions & 10 deletions client/src/Auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import history from '../history';
import auth0 from 'auth0-js';
import { AUTH_CONFIG } from './auth0-config';
import $ from 'jquery'

const Sentry = require('../Sentry/logger');
import { sendMessage, sendMessageExtra } from '../Sentry/logger';

/* Auth Class */

Expand Down Expand Up @@ -48,7 +47,7 @@ export default class Auth {
history.replace('/profile');
} else if (err) {
history.replace('/profile');
console.log(err);
sendMessageExtra('Error in authentication',err.error);
alert(`Error: ${err.error}. Check the console for further details.`);
}
});
Expand Down Expand Up @@ -96,7 +95,7 @@ export default class Auth {
return new Promise((resolve, reject) => {
const accessToken = localStorage.getItem('access_token');
if (!accessToken) {
Sentry.captureMessage('No access token found');
sendMessage('No access token found');
reject(new Error('No access token found'));
}
resolve(accessToken);
Expand All @@ -109,7 +108,7 @@ export default class Auth {
return new Promise((resolve, reject) => {
const idToken = localStorage.getItem('id_token');
if (!idToken) {
Sentry.captureMessage('No id token found');
sendMessage('No id token found');
reject(new Error('No id token found'));
}
resolve(idToken);
Expand All @@ -132,7 +131,7 @@ export default class Auth {
});
})
.catch((err) => {
Sentry.captureMessage('Error while getting profile');
sendMessageExtra('Error while getting profile',err);
return reject(err);
});
});
Expand Down Expand Up @@ -161,13 +160,13 @@ export default class Auth {
return resolve(result);
},
error: err => {
Sentry.captureMessage('Error in AJAX call for gettingMetaProfile data');
sendMessageExtra('Error in AJAX call for getting MetaProfileData',err);
return reject(err);
}
});
})
.catch(err => {
Sentry.captureMessage('Error while getting meta profile data');
sendMessageExtra('Error while getting meta profile data',err);
reject(err);
});
});
Expand Down Expand Up @@ -197,13 +196,13 @@ export default class Auth {
resolve(result);
},
error: err => {
Sentry.captureMessage('Error in AJAX call for update data');
sendMessageExtra('Error in AJAX call for update data',err);
reject(err);
}
});
})
.catch(err => {
Sentry.captureMessage('Error while updating data');
sendMessageExtra('Error while updating data',err);
reject(err);
});
});
Expand Down
20 changes: 18 additions & 2 deletions client/src/Sentry/logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
const Sentry = require('@sentry/browser');

Sentry.init({dsn: ""});
Sentry.init({dsn: `${process.env.REACT_APP_SENTRY_DSN}` });

module.exports = Sentry;
const sendMessage = ( msg ) => {
Sentry.captureMessage(msg);
}

const sendMessageExtra = ( msg, obj ) => {
Sentry.captureMessage(msg, {extra: obj});
}

const setUserName = ( name ) => {
Sentry.setUser({ username: name })
}

module.exports = {
sendMessage,
setUserName,
sendMessageExtra
};
5 changes: 2 additions & 3 deletions client/src/components/Profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import ProfilePicture from './ProfilePicture';
import ProfileSettings from './ProfileSettings';
import Sidebar from './Sidebar';
import DailyEmission from './DailyEmission';

const Sentry = require('../../Sentry/logger')
import { setUserName } from '../../Sentry/logger'

/* Extended react.Component class as Profile */

Expand Down Expand Up @@ -46,7 +45,7 @@ export default class Profile extends Component {
given_name: profile.given_name,
family_name: profile.family_name
});
Sentry.setUser({username: profile.nickname});
setUserName(profile.nickname);
})
.catch(err => {
console.log(err);
Expand Down
3 changes: 1 addition & 2 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';

import * as Sentry from '@sentry/browser';
import 'semantic-ui-css/semantic.min.css'
import App from './App';
import * as serviceWorker from './serviceWorker';

Sentry.init({dsn: ""});
import './Sentry/logger';

ReactDOM.render(<App />, document.getElementById('root'));

Expand Down
2 changes: 1 addition & 1 deletion framework/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Logger = new winston.Logger({
new winston.transports.File({ level: 'debug', filename: 'dev.log' }),
new Sentry({
level: 'error',
dsn: ''
dsn: `${process.env.SENTRY_DSN}`
})
],
});
Expand Down
1 change: 0 additions & 1 deletion framework/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ redisClient
// if the connection throws an error
.on('error', (err) => {
Logger.error(`Redis connection failed: ${err}`);
throw new Error(`Redis connection failed: ${err}`);
})
// if the connection is connected
.on('connect', () => Logger.info('Redis connected successfully'));
Expand Down

0 comments on commit dcd7531

Please sign in to comment.