mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +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 });
|
||||
});
|
||||
};
|
||||
|
||||
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 *
|
||||
*------------------------------------------------------------------*/
|
||||
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 *
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
@ -37,5 +37,5 @@
|
||||
"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}`;
|
||||
localStorage.setItem('FBIdToken', FBIdToken);
|
||||
axios.defaults.headers.common['Authorization'] = FBIdToken;
|
||||
dispatch(getProfileInfo());
|
||||
dispatch(getUserData());
|
||||
dispatch({ type: CLEAR_ERRORS })
|
||||
// Redirects to home page
|
||||
history.push('/home');
|
||||
@ -23,13 +23,13 @@ export const loginUser = (loginData, history) => (dispatch) => {
|
||||
});
|
||||
}
|
||||
|
||||
// export const getProfileInfo = () => (dispatch) => {
|
||||
// axios.get('/getProfileInfo')
|
||||
// .then((res) => {
|
||||
// dispatch({
|
||||
// type: SET_USER,
|
||||
// payload: res.data,
|
||||
// })
|
||||
// })
|
||||
// .catch((err) => console.error(err));
|
||||
// }
|
||||
export const getUserData = () => (dispatch) => {
|
||||
axios.get('/user')
|
||||
.then((res) => {
|
||||
dispatch({
|
||||
type: SET_USER,
|
||||
payload: res.data,
|
||||
})
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user