Skip to content

Commit

Permalink
logout
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhao committed Aug 2, 2018
1 parent 4df1342 commit 8b67ac8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions public/api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import express from 'express';
var express = require('express');
const router = express.Router();

// Transform req & res to have the same API as express
Expand Down Expand Up @@ -27,7 +27,7 @@ router.post('/logout', (req, res) => {
res.json({ ok: true });
});
//Export the server middleware
export default {
return {
path: '/api',
handler: router
};
9 changes: 9 additions & 0 deletions public/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<p>
<i>You can also refresh this page, you'll still be connected!</i>
</p>
<button @click="logout">LOGOUT</button>
</div>
</div>
</div>
Expand All @@ -44,6 +45,14 @@ export default {
console.log('e', e);
this.formError = e.message;
}
},
async logout() {
try {
await this.$store.dispatch('logout');
} catch (e) {
console.log('e', e);
this.formError = e.message;
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions public/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const store = () => {
const { data } = await axios.post('/api/login', { username, password });
console.log(data);
commit('SET_USER', data);
},
async logout({commit}){
await axios.post('/api/logout');
commit('SET_USER', null);
}
}
});
Expand Down

0 comments on commit 8b67ac8

Please sign in to comment.