aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/basicAuth/store.ts
blob: 489eac087768766aa9f7fc2040f650f0ed61d35b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { ipcRenderer } from 'electron';
import { observable } from 'mobx';

const debug = require('../../preload-safe-debug')('Ferdium:feature:basicAuth');

interface IAuthInfo {
  host: string;
  port: number;
}
interface IDefaultState {
  isModalVisible: boolean;
  service: null;
  authInfo: IAuthInfo | null;
}

const defaultState: IDefaultState = {
  isModalVisible: true,
  service: null,
  authInfo: null,
};

export const state = observable(defaultState);

export function resetState() {
  Object.assign(state, defaultState);
}
export function sendCredentials(user, password) {
  debug('Sending credentials to main', user, password);

  ipcRenderer.send('feature-basic-auth-credentials', {
    user,
    password,
  });
}

export function cancelLogin() {
  debug('Cancel basic auth event');

  ipcRenderer.send('feature-basic-auth-cancel');
}