refactor auth and api/index to ensure token verified and sent to dispatch ADD_USER
This commit is contained in:
parent
fb0641fa0d
commit
25caa3124d
6 changed files with 2898 additions and 2278 deletions
5150
play-node-go/package-lock.json
generated
5150
play-node-go/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -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",
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -12,7 +12,7 @@ const indexService = async () => {
|
|||
{method: 'GET', credentials: 'include', headers: headers}
|
||||
)
|
||||
.then(res => {
|
||||
return res;
|
||||
return res.text();
|
||||
}).catch(err => {
|
||||
return err;
|
||||
});
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue