Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function loginUser(creds) {
- const data = querystring.stringify({_username: creds.username, _password: creds.password});
- let config = {
- method: 'POST',
- headers: { 'Content-Type':'application/x-www-form-urlencoded' },
- body: data
- };
- return dispatch => {
- // We dispatch requestLogin to kickoff the call to the API
- dispatch(requestLogin(creds));
- return fetch(BASE_URL+'login_check', config)
- .then(response =>
- response.json().then(user => ({ user, response }))
- ).then(({ user, response }) => {
- if (!response.ok) {
- // If there was a problem, we want to
- // dispatch the error condition
- dispatch(loginError(user.message));
- return Promise.reject(user)
- } else {
- localStorage.setItem('idToken', user.token);
- let token = localStorage.getItem('idToken')
- console.log(token);
- // if I remove this log, my token is returned as null during post.
- dispatch(receiveLogin(user));
- }
- }).catch(err => console.log("Error: ", err))
- }
- }
- import axios from 'axios';
- import {BASE_URL} from './middleware/api';
- import {reset} from 'redux-form';
- let token = localStorage.getItem('idToken');
- const AuthStr = 'Bearer '.concat(token);
- let headers ={
- headers: { 'Content-Type':'application/json','Authorization' : AuthStr }
- };
- export default (async function showResults(values, dispatch) {
- console.log(AuthStr);
- axios.post(BASE_URL + 'human/new', values, headers)
- .then(function (response) {
- console.log(response);
- alert("Your submit was successful");
- //dispatch(reset('wizard'));
- }).catch(function (error) {
- console.log(error.response);
- alert(error.response.statusText);
- });
- });
- getHouses = (e) => {
- let token = localStorage.getItem('idToken') || null;
- const AuthStr = 'Bearer '.concat(token);
- axios.get(BASE_URL + 'household/list', { headers: { Authorization: AuthStr } }).then((response) =>
- {
- let myData = response.data;
- let list = [];
- let key =[];
- for (let i = 0; i < myData._embedded.length; i++) {
- let embedded = myData._embedded[i];
- list.push(embedded.friendlyName);
- key.push(embedded.id);
- }
- this.setState({data: list, key: key});
- })
- .catch((error) => {
- console.log('error' + error);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement