diff --git a/server/routes/auth.js b/server/routes/auth.js index 188aec9..9647885 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -11,7 +11,7 @@ router.post('/auth/login', return res.status(400).json({errors: info}); req.logIn(user, () => { - return res.status(200).json({success: `logged in ${user.id}`}); + return res.status(200).json({user: req.user}); }); })(req, res, next); } diff --git a/web/src/store/index.ts b/web/src/store/index.ts index a3e5290..4ba7fe6 100644 --- a/web/src/store/index.ts +++ b/web/src/store/index.ts @@ -30,7 +30,7 @@ export default createStore({ data: qs.stringify({...user}) }) .then((resp: AxiosResponse) => { - commit("auth_success", user); + commit("auth_success", resp.data.user); resolve(resp) }) .catch((err: Error) => { @@ -63,6 +63,11 @@ export default createStore({ url: '/auth/current_user' }) .then((resp: AxiosResponse) => { + if (resp.data === "") { + commit('auth_error') + return + } + commit("auth_success", resp.data); resolve(resp) }) @@ -76,6 +81,7 @@ export default createStore({ modules: {}, getters: { isLoggedIn: state => state.status, + user: state => state.user }, plugins: [createPersistedState()] })