refactor auth and api/index to ensure token verified and sent to dispatch ADD_USER
This commit is contained in:
parent
5fa43f8b7e
commit
465a3342f2
6 changed files with 2898 additions and 2278 deletions
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mars/heroku-js-runtime-env": "^3.0.2",
|
"@mars/heroku-js-runtime-env": "^3.0.2",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^7.1.2",
|
||||||
"axios": "^0.19.1",
|
|
||||||
"flow-bin": "^0.114.0",
|
"flow-bin": "^0.114.0",
|
||||||
"node-sass": "^4.13.0",
|
"node-sass": "^4.13.0",
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
|
|
|
@ -24,17 +24,20 @@ function App() {
|
||||||
|
|
||||||
const fetchIndexAPI = async () => {
|
const fetchIndexAPI = async () => {
|
||||||
const response = await indexServices.indexService();
|
const response = await indexServices.indexService();
|
||||||
if (response.body) {
|
if (response) {
|
||||||
console.log(response.body)
|
|
||||||
const action = {
|
const action = {
|
||||||
type: 'INDEX',
|
type: 'INDEX',
|
||||||
message: 'SET_USER',
|
message: 'SET_USER',
|
||||||
body: response.body
|
body: response
|
||||||
}
|
}
|
||||||
dispatch(action)
|
dispatch(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchIndexAPI();
|
||||||
|
}, [])
|
||||||
|
|
||||||
const socketConnect = () => {
|
const socketConnect = () => {
|
||||||
socket.emit('connect');
|
socket.emit('connect');
|
||||||
socket.on('connected', data => setSocketData('socket connected'));
|
socket.on('connected', data => setSocketData('socket connected'));
|
||||||
|
@ -43,13 +46,11 @@ function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchIndexAPI();
|
|
||||||
socketConnect();
|
socketConnect();
|
||||||
}, [socketData, state.user])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
{/* {fetchOnLoad()}; */}
|
|
||||||
|
|
||||||
<div data-testid="App" className="App">
|
<div data-testid="App" className="App">
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|
|
@ -5,8 +5,8 @@ export const indexReducer = (state: state, action: action):state => {
|
||||||
switch(action.message) {
|
switch(action.message) {
|
||||||
|
|
||||||
case 'SET_USER':
|
case 'SET_USER':
|
||||||
const parsedData = indexDataParse(action.body);
|
const user = indexDataParse(action.body);
|
||||||
return state;
|
return {...state, user};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
@ -14,5 +14,6 @@ export const indexReducer = (state: state, action: action):state => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function indexDataParse(indexData) {
|
function indexDataParse(indexData) {
|
||||||
console.log(indexData)
|
const user = JSON.parse(indexData);
|
||||||
|
return user
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ const indexService = async () => {
|
||||||
{method: 'GET', credentials: 'include', headers: headers}
|
{method: 'GET', credentials: 'include', headers: headers}
|
||||||
)
|
)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
return res;
|
return res.text();
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
return err;
|
return err;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import Axios from 'axios';
|
|
||||||
|
|
||||||
const authEndpoint = config.authAddress;
|
const authEndpoint = config.authAddress;
|
||||||
const signupEndpoint = `${authEndpoint}/signup`
|
const signupEndpoint = `${authEndpoint}/signup`
|
||||||
|
@ -15,8 +14,6 @@ const loginService = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const signupService = async (formData) => {
|
const signupService = async (formData) => {
|
||||||
// const response = await Axios.post(signupEndpoint, {...formData }, {credentials: 'include', headers: headers})
|
|
||||||
console.log(formData)
|
|
||||||
const response = await fetch(signupEndpoint, {
|
const response = await fetch(signupEndpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
|
Loading…
Reference in a new issue