Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
vue-cookie plugin installed and implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilFreelancer committed Feb 9, 2020
1 parent 82bc987 commit 408e411
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"font-awesome": "^4.7.0",
"apollo-cache-inmemory": "^1.6.5",
"apollo-client": "^2.6.8",
"apollo-link": "^1.2.13",
Expand All @@ -19,6 +18,7 @@
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"deepmerge": "^4.2.2",
"font-awesome": "^4.7.0",
"graphql": "^14.6.0",
"graphql-anywhere": "^4.2.6",
"graphql-tag": "^2.10.3",
Expand All @@ -32,6 +32,7 @@
"startbootstrap-sb-admin-2": "^4.0.7",
"vue": "^2.5.17",
"vue-apollo": "^3.0.3",
"vue-cookies": "^1.6.1",
"vue-router": "^3.1.5",
"vue-table-component": "^1.9.2",
"vue-template-compiler": "^2.6.10",
Expand Down
11 changes: 8 additions & 3 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import store from "./store";
import routes from './routes';

// Plugins
import VueApollo from 'vue-apollo';
import VueRouter from 'vue-router';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import VueRouter from 'vue-router';
import VueCookies from 'vue-cookies';

// Main components
import App from "./components/App";

// Basic uses
Vue.use(VueApollo);
Vue.use(VueRouter);
Vue.use(VueCookies);

// Preconfigure Vue-Router
const router = new VueRouter({
Expand All @@ -26,9 +29,11 @@ const router = new VueRouter({
});

router.beforeEach((to, from, next) => {
if (!store.state.token && to.name !== 'login') {
var token = Vue.$cookies.get('token');
if (!store.state.token && !token && to.name !== 'login') {
next({name: 'login'});
} else {
store.commit('SET_TOKEN', token);
next();
}
});
Expand Down
4 changes: 1 addition & 3 deletions resources/js/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@
* Initiate login logic based on API token
*/
login() {
console.log(this.form);
this.$store.dispatch('login', this.form)
.then(response => {
console.log(response);
if (!!this.$store.state.token) {
Vue.$cookies.set('token', this.$store.state.token);
this.error = null;
this.$router.push({name: 'dashboard'});
}
Expand Down

0 comments on commit 408e411

Please sign in to comment.