refactor auth and api/index to ensure token verified and sent to dispatch ADD_USER

This commit is contained in:
Sorrel Bri 2020-01-17 20:24:57 -08:00 committed by sorrelbri
parent ff2e1e82b2
commit d10774c161
6 changed files with 2898 additions and 2278 deletions

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,6 @@
"dependencies": {
"@mars/heroku-js-runtime-env": "^3.0.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.1",
"flow-bin": "^0.114.0",
"node-sass": "^4.13.0",
"react": "^16.12.0",

View file

@ -24,17 +24,20 @@ function App() {
const fetchIndexAPI = async () => {
const response = await indexServices.indexService();
if (response.body) {
console.log(response.body)
if (response) {
const action = {
type: 'INDEX',
message: 'SET_USER',
body: response.body
body: response
}
dispatch(action)
}
}
useEffect(() => {
fetchIndexAPI();
}, [])
const socketConnect = () => {
socket.emit('connect');
socket.on('connected', data => setSocketData('socket connected'));
@ -43,13 +46,11 @@ function App() {
}
useEffect(() => {
fetchIndexAPI();
socketConnect();
}, [socketData, state.user])
}, [])
return (
<Router>
{/* {fetchOnLoad()}; */}
<div data-testid="App" className="App">
<Switch>

View file

@ -5,8 +5,8 @@ export const indexReducer = (state: state, action: action):state => {
switch(action.message) {
case 'SET_USER':
const parsedData = indexDataParse(action.body);
return state;
const user = indexDataParse(action.body);
return {...state, user};
default:
return state;
@ -14,5 +14,6 @@ export const indexReducer = (state: state, action: action):state => {
}
function indexDataParse(indexData) {
console.log(indexData)
const user = JSON.parse(indexData);
return user
}

View file

@ -12,7 +12,7 @@ const indexService = async () => {
{method: 'GET', credentials: 'include', headers: headers}
)
.then(res => {
return res;
return res.text();
}).catch(err => {
return err;
});

View file

@ -1,5 +1,4 @@
import config from '../config';
import Axios from 'axios';
const authEndpoint = config.authAddress;
const signupEndpoint = `${authEndpoint}/signup`
@ -15,8 +14,6 @@ const loginService = () => {
}
const signupService = async (formData) => {
// const response = await Axios.post(signupEndpoint, {...formData }, {credentials: 'include', headers: headers})
console.log(formData)
const response = await fetch(signupEndpoint, {
method: 'POST',
credentials: 'include',