Adrià Vilanova Martínez | f7ee658 | 2021-09-02 21:53:28 +0200 | [diff] [blame] | 1 | import {createStore} from 'vuex'; |
| 2 | |
| 3 | import {KillSwitchServicePromiseClient} from '../api_proto/kill_switch_grpc_web_pb.js'; |
| 4 | |
| 5 | export const store = createStore({ |
| 6 | state() { |
| 7 | return { |
| 8 | jwtToken: localStorage.getItem('jwtToken'), |
| 9 | client: null, |
| 10 | }; |
| 11 | }, |
| 12 | mutations: { |
| 13 | setJwtToken(state, token) { |
| 14 | if (token == null) |
| 15 | localStorage.removeItem('jwtToken'); |
| 16 | else |
| 17 | localStorage.jwtToken = token; |
| 18 | |
| 19 | state.jwtToken = token; |
| 20 | }, |
| 21 | }, |
| 22 | getters: { |
| 23 | getJwtToken(state) { |
| 24 | return state.jwtToken; |
| 25 | }, |
| 26 | isSignedIn(state) { |
| 27 | return state.jwtToken != null; |
| 28 | }, |
| 29 | }, |
| 30 | actions: { |
| 31 | connectClient(store, host) { |
Adrià Vilanova Martínez | 035b543 | 2021-09-03 14:16:59 +0200 | [diff] [blame] | 32 | // We enable the dev tools in case they are useful sometime in the future. |
| 33 | const enableDevTools = window.__GRPCWEB_DEVTOOLS__ || (() => {}); |
Adrià Vilanova Martínez | f7ee658 | 2021-09-02 21:53:28 +0200 | [diff] [blame] | 34 | store.state.client = new KillSwitchServicePromiseClient(host, null, null); |
Adrià Vilanova Martínez | 035b543 | 2021-09-03 14:16:59 +0200 | [diff] [blame] | 35 | enableDevTools([ |
| 36 | store.state.client, |
| 37 | ]); |
Adrià Vilanova Martínez | f7ee658 | 2021-09-02 21:53:28 +0200 | [diff] [blame] | 38 | }, |
| 39 | }, |
| 40 | }); |