From 32fd03a29f5d7222746d18476bfeb74ab675275d Mon Sep 17 00:00:00 2001 From: Sumanth Date: Tue, 22 Jan 2019 08:24:10 +0530 Subject: [PATCH] axios config --- .../actions/signupPage/signupPageActions.js | 14 ++++++++--- .../landingPage/signinContainer.jsx | 2 +- .../landingPage/signupContainer.jsx | 6 ++--- view/js/config/axiosServices.js | 7 ++++++ view/js/services/signin/signin.js | 17 ++++++++++++++ .../tokenValidityChecker.js | 23 +++++++++++++++++++ 6 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 view/js/config/axiosServices.js create mode 100644 view/js/services/tokenValidityChecker/tokenValidityChecker.js diff --git a/view/js/actions/signupPage/signupPageActions.js b/view/js/actions/signupPage/signupPageActions.js index 4c56606..e0acf37 100644 --- a/view/js/actions/signupPage/signupPageActions.js +++ b/view/js/actions/signupPage/signupPageActions.js @@ -2,14 +2,22 @@ import signupPageActionTypes from './signupPageActionTypes'; import { AuthActions } from '../auth/auth'; import history from '../../routes/history'; import {signup} from '../../services/signup/signup' +import tokenVC from '../../services/tokenValidityChecker/tokenValidityChecker'; + +import AxiosConfig from '../../config/axiosServices'; + const singupPageActions = { usernameInputHandler : payload => ({type: signupPageActionTypes.USERNAME_INPUT, payload}), passwordInputHandler : payload => ({type: signupPageActionTypes.PASSWORD_INPUT, payload}), submit: payload => (dispatch) => { - signup(payload).then(response => { - dispatch(AuthActions.tokenReceived(response)); - history.push(response.redirect); + console.log('axios config is : ', AxiosConfig); + tokenVC().then(response => { + console.log('tokennnnnn response', response); }); + // signup(payload).then(response => { + // dispatch(AuthActions.tokenReceived(response)); + // history.push(response.redirect); + // }); } } diff --git a/view/js/components/landingPage/signinContainer.jsx b/view/js/components/landingPage/signinContainer.jsx index 101801f..5f2c18f 100644 --- a/view/js/components/landingPage/signinContainer.jsx +++ b/view/js/components/landingPage/signinContainer.jsx @@ -92,7 +92,7 @@ class Signin extends Component{ - + diff --git a/view/js/components/landingPage/signupContainer.jsx b/view/js/components/landingPage/signupContainer.jsx index ef20bc1..a8b632c 100644 --- a/view/js/components/landingPage/signupContainer.jsx +++ b/view/js/components/landingPage/signupContainer.jsx @@ -26,7 +26,7 @@ class Signup extends Component{ this.props.dispatch(signupPageActions.passwordInputHandler(e.target.value))}/>
- this.submitHandler()} /> + this.submitHandler()} />
@@ -36,8 +36,8 @@ class Signup extends Component{ - - + + diff --git a/view/js/config/axiosServices.js b/view/js/config/axiosServices.js new file mode 100644 index 0000000..8a881dc --- /dev/null +++ b/view/js/config/axiosServices.js @@ -0,0 +1,7 @@ +let token = localStorage.getItem('JWT_TOKEN'); + +const config = { + headers: {"Authorization": `${token}`} +} + +export default config; \ No newline at end of file diff --git a/view/js/services/signin/signin.js b/view/js/services/signin/signin.js index e69de29..bc5d4bd 100644 --- a/view/js/services/signin/signin.js +++ b/view/js/services/signin/signin.js @@ -0,0 +1,17 @@ +import {raiseStatus} from '../../scripts/https'; +import axios from 'axios'; +const signin = (payload) => fetch('/api/signup',{ + method: 'POST', + headers:{ + 'Content-Type': 'application/json' + }, + body: JSON.stringify(payload) + }) + .then(raiseStatus); + // .catch(err=>{ + // console.log('error was found at service,', err); + // }); + +export { + signup +} diff --git a/view/js/services/tokenValidityChecker/tokenValidityChecker.js b/view/js/services/tokenValidityChecker/tokenValidityChecker.js new file mode 100644 index 0000000..e1ae459 --- /dev/null +++ b/view/js/services/tokenValidityChecker/tokenValidityChecker.js @@ -0,0 +1,23 @@ +import {raiseStatus} from '../../scripts/https'; +import axios from 'axios'; +import axiosConfig from '../../config/axiosServices'; + +const tokenVC = () => axios.get('/api/authorized',axiosConfig).then(res=>{ + console.log('validity checker response', res); +}); + + + +const signin = (payload) => fetch('/api/signup',{ + method: 'POST', + headers:{ + 'Content-Type': 'application/json' + }, + body: JSON.stringify(payload) + }) + .then(raiseStatus); + // .catch(err=>{ + // console.log('error was found at service,', err); + // }); + +export default tokenVC;