mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Redux saves user data on login
This commit is contained in:
parent
8de496826a
commit
f14e8bd970
@ -214,3 +214,20 @@ exports.getUserDetails = (req, res) => {
|
|||||||
return res.status(500).json({ error: err.code });
|
return res.status(500).json({ error: err.code });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getAuthenticatedUser = (req, res) => {
|
||||||
|
let userData = {};
|
||||||
|
db.doc(`/users/${req.user.handle}`)
|
||||||
|
.get()
|
||||||
|
.then((doc) => {
|
||||||
|
if (doc.exists) {
|
||||||
|
userData.credentials = doc.data();
|
||||||
|
return res.status(200).json({userData});
|
||||||
|
} else {
|
||||||
|
return res.status(400).json({error: "User not found."})
|
||||||
|
}})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: err.code });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@ -10,6 +10,7 @@ app.use(cors());
|
|||||||
* handlers/users.js *
|
* handlers/users.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {
|
const {
|
||||||
|
getAuthenticatedUser,
|
||||||
getUserDetails,
|
getUserDetails,
|
||||||
getProfileInfo,
|
getProfileInfo,
|
||||||
login,
|
login,
|
||||||
@ -34,6 +35,8 @@ app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
|||||||
// Updates the currently logged in user's profile information
|
// Updates the currently logged in user's profile information
|
||||||
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
||||||
|
|
||||||
|
app.get("/user", fbAuth, getAuthenticatedUser);
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
|
|||||||
@ -37,5 +37,5 @@
|
|||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"proxy": " http://localhost:5001/twistter-e4649/us-central1/api"
|
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export const loginUser = (loginData, history) => (dispatch) => {
|
|||||||
const FBIdToken = `Bearer ${res.data.token}`;
|
const FBIdToken = `Bearer ${res.data.token}`;
|
||||||
localStorage.setItem('FBIdToken', FBIdToken);
|
localStorage.setItem('FBIdToken', FBIdToken);
|
||||||
axios.defaults.headers.common['Authorization'] = FBIdToken;
|
axios.defaults.headers.common['Authorization'] = FBIdToken;
|
||||||
dispatch(getProfileInfo());
|
dispatch(getUserData());
|
||||||
dispatch({ type: CLEAR_ERRORS })
|
dispatch({ type: CLEAR_ERRORS })
|
||||||
// Redirects to home page
|
// Redirects to home page
|
||||||
history.push('/home');
|
history.push('/home');
|
||||||
@ -23,13 +23,13 @@ export const loginUser = (loginData, history) => (dispatch) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// export const getProfileInfo = () => (dispatch) => {
|
export const getUserData = () => (dispatch) => {
|
||||||
// axios.get('/getProfileInfo')
|
axios.get('/user')
|
||||||
// .then((res) => {
|
.then((res) => {
|
||||||
// dispatch({
|
dispatch({
|
||||||
// type: SET_USER,
|
type: SET_USER,
|
||||||
// payload: res.data,
|
payload: res.data,
|
||||||
// })
|
})
|
||||||
// })
|
})
|
||||||
// .catch((err) => console.error(err));
|
.catch((err) => console.error(err));
|
||||||
// }
|
}
|
||||||
Loading…
Reference in New Issue
Block a user