Browse Source

🔑 Fix getCurrentUser in web

Router would let request through even if req.user  was undefined
main
Haris Razis 4 years ago
parent
commit
b73f6c2f38
  1. 2
      server/routes/auth.js
  2. 8
      web/src/store/index.ts

2
server/routes/auth.js

@ -11,7 +11,7 @@ router.post('/auth/login',
return res.status(400).json({errors: info}); return res.status(400).json({errors: info});
req.logIn(user, () => { req.logIn(user, () => {
return res.status(200).json({success: `logged in ${user.id}`}); return res.status(200).json({user: req.user});
}); });
})(req, res, next); })(req, res, next);
} }

8
web/src/store/index.ts

@ -30,7 +30,7 @@ export default createStore({
data: qs.stringify({...user}) data: qs.stringify({...user})
}) })
.then((resp: AxiosResponse) => { .then((resp: AxiosResponse) => {
commit("auth_success", user); commit("auth_success", resp.data.user);
resolve(resp) resolve(resp)
}) })
.catch((err: Error) => { .catch((err: Error) => {
@ -63,6 +63,11 @@ export default createStore({
url: '/auth/current_user' url: '/auth/current_user'
}) })
.then((resp: AxiosResponse) => { .then((resp: AxiosResponse) => {
if (resp.data === "") {
commit('auth_error')
return
}
commit("auth_success", resp.data); commit("auth_success", resp.data);
resolve(resp) resolve(resp)
}) })
@ -76,6 +81,7 @@ export default createStore({
modules: {}, modules: {},
getters: { getters: {
isLoggedIn: state => state.status, isLoggedIn: state => state.status,
user: state => state.user
}, },
plugins: [createPersistedState()] plugins: [createPersistedState()]
}) })

Loading…
Cancel
Save