Skip to content

Commit

Permalink
Merge 187edf3 into 5130ba3
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrogha committed May 13, 2019
2 parents 5130ba3 + 187edf3 commit 0c4ea6f
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baseURL=
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
},
"plugins": ["jest", "react"],
"rules": {
"no-param-reassign":"off",
"max-len": [1, 80, 2],
"react/jsx-uses-react":1,
"react/react-in-jsx-scope": 1,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules/
coverage/
src/.DS_Store
.env
5 changes: 0 additions & 5 deletions dist/config.js

This file was deleted.

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"coveralls": "^3.0.3",
"dotenv": "^8.0.0",
"enzyme-to-json": "^3.3.5",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
Expand Down
5 changes: 2 additions & 3 deletions src/actions/signupSigninActions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { notify } from 'react-notify-toast';
import axios from 'axios';
import config from '../../dist/config';

export const signUpUser = (user, history) => () => {
axios
.post(`${config.baseURL}/register/`, user)
.post(`${process.env.baseURL}/users/register/`, user)
.then(() => {
notify.show('Registration successful', 'success', 4000);
history.push('/login');
Expand All @@ -18,7 +17,7 @@ export const signUpUser = (user, history) => () => {

export const signInUser = (user, history) => () => {
axios
.post(`${config.baseURL}/login/`, user)
.post(`${process.env.baseURL}/users/login/`, user)
.then((response) => {
localStorage.setItem('accessToken', response.data.user.token);
notify.show('Login successful', 'success', 4000);
Expand Down
15 changes: 8 additions & 7 deletions src/helpers/axiosInstance.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import axios from 'axios';

const axiosInstance = axios.create({
baseURL: 'https://ah-backend.herokuapp.com',
headers: { Authorization: `Bearer ${localStorage.getItem('accessToken')}` }
baseURL: process.env.baseURL,
headers: { Authorization: `Bearer ${localStorage.getItem('accessToken')}` },
});

axiosInstance.interceptors.request.use((config) => {
if (localStorage.getItem('accessToken') && config.headers.Authorization === 'Bearer null') {
config.headers.Authorization = `Bearer ${localStorage.getItem('accessToken')}`;
}
return config;
});
if (localStorage.getItem('accessToken')
&& config.headers.Authorization === 'Bearer null') {
config.headers.Authorization = `Bearer ${localStorage.getItem('accessToken')}`;
}
return config;
});

export default axiosInstance;
11 changes: 10 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
const path = require('path');
const webpack = require('webpack');
const dotenv = require('dotenv');
const HtmlWebPackPlugin = require('html-webpack-plugin');

const env = dotenv.config().parsed;

const envKeys = Object.keys(env).reduce((prev, next) => {
const previous = prev;
previous[`process.env.${next}`] = JSON.stringify(env[next]);
return previous;
}, {});

module.exports = {
entry: './src/index.jsx',
Expand Down Expand Up @@ -39,13 +48,13 @@ module.exports = {
},
],
},

],
},
plugins: [
new HtmlWebPackPlugin({
template: './src/index.html',
}),
new webpack.DefinePlugin(envKeys),
],
devServer: {
historyApiFallback: true,
Expand Down

0 comments on commit 0c4ea6f

Please sign in to comment.