blob: 0666838f86c1170be7ee7493b5739dd5605ce199 [file] [log] [blame]
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +02001import {createStore} from 'vuex';
2
3import {KillSwitchServicePromiseClient} from '../api_proto/kill_switch_grpc_web_pb.js';
4
5export 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ínez035b5432021-09-03 14:16:59 +020032 // We enable the dev tools in case they are useful sometime in the future.
33 const enableDevTools = window.__GRPCWEB_DEVTOOLS__ || (() => {});
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +020034 store.state.client = new KillSwitchServicePromiseClient(host, null, null);
Adrià Vilanova Martínez035b5432021-09-03 14:16:59 +020035 enableDevTools([
36 store.state.client,
37 ]);
Adrià Vilanova Martínezf7ee6582021-09-02 21:53:28 +020038 },
39 },
40});