comparison client/src/stores/user.js @ 13:88d0d60924cf

Move vuejs app into subdir `client` Using a subdirectory for the web application keeps more structure in the repo.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 20 Jun 2018 17:02:06 +0200
parents src/stores/user.js@7c1bde663c8e
children 992e17912405
comparison
equal deleted inserted replaced
12:000adddf74c8 13:88d0d60924cf
1 import { HTTP } from "../lib/http";
2
3 const User = {
4 namespaced: true,
5 state: {
6 authenticated: false
7 },
8 getters: {
9 authenticated: state => {
10 return state.authenticated;
11 }
12 },
13 mutations: {
14 auth_success: (state, token) => {
15 state.authenticated = true;
16 sessionStorage.setItem("token", token);
17 },
18 auth_failure: state => {
19 state.authenticated = false;
20 sessionStorage.removeItem("token");
21 }
22 },
23 actions: {
24 login({ commit }, user) {
25 return new Promise((resolve, reject) => {
26 HTTP.post("/token", user)
27 .then(response => {
28 let token = response.data;
29 commit("auth_success", token);
30 resolve(response);
31 })
32 .catch(error => {
33 commit("auth_failure");
34 reject(error);
35 });
36 });
37 }
38 }
39 };
40
41 export default User;