Redux saves user data on login

This commit is contained in:
2019-10-03 10:58:45 -04:00
parent 8de496826a
commit f14e8bd970
4 changed files with 32 additions and 12 deletions

View File

@@ -214,3 +214,20 @@ exports.getUserDetails = (req, res) => {
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 });
});
};

View File

@@ -10,6 +10,7 @@ app.use(cors());
* handlers/users.js *
*------------------------------------------------------------------*/
const {
getAuthenticatedUser,
getUserDetails,
getProfileInfo,
login,
@@ -34,6 +35,8 @@ app.get("/getProfileInfo", fbAuth, getProfileInfo);
// Updates the currently logged in user's profile information
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
app.get("/user", fbAuth, getAuthenticatedUser);
/*------------------------------------------------------------------*
* handlers/post.js *
*------------------------------------------------------------------*/