All files / web/modules/auth actions.ts

53.85% Statements 7/13
100% Branches 0/0
0% Functions 0/6
58.33% Lines 7/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 1191x                                         1x                                 1x                                     1x                                     1x                           1x                           1x                            
import {
  AUTH_LOGOUT_USER,
  AUTH_SET_AUTH_DATA,
  AUTH_SET_AUTH_STATE,
  AUTH_SET_IS_LOADING,
  AUTH_SET_NEW_PASSWORD,
  AUTH_SIGN_IN,
  AUTH_STATE,
} from './constants';
import { IAuthData } from './reducer';
 
// Set auth state
export type AuthSetAuthStateAction = (
  authState: AUTH_STATE,
) => IAuthSetAuthStateActionResponse;
 
export interface IAuthSetAuthStateActionResponse {
  type: AUTH_SET_AUTH_STATE;
  authState: AUTH_STATE;
}
 
export const authSetAuthStateAction: AuthSetAuthStateAction = (
  authState: AUTH_STATE,
) => ({
  type: AUTH_SET_AUTH_STATE,
  authState,
});
 
// Set auth data
export type AuthSetAuthDataAction = (
  authData: IAuthData,
) => IAuthSetAuthDataActionResponse;
 
export interface IAuthSetAuthDataActionResponse {
  type: AUTH_SET_AUTH_DATA;
  authData: IAuthData;
}
 
export const authSetAuthDataAction: AuthSetAuthDataAction = (
  authData: IAuthData,
) => ({
  type: AUTH_SET_AUTH_DATA,
  authData,
});
 
// Sign in
export type AuthSignInAction = (
  username: string,
  password: string,
) => IAuthSignInActionResponse;
 
export interface IAuthSignInActionResponse {
  type: AUTH_SIGN_IN;
  username: string;
  password: string;
}
 
export const authSignInAction: AuthSignInAction = (
  username: string,
  password: string,
) => ({
  type: AUTH_SIGN_IN,
  username,
  password,
});
 
// Set new password
export type AuthSetNewPasswordAction = (
  password: string,
) => IAuthSetNewPasswordActionResponse;
 
export interface IAuthSetNewPasswordActionResponse {
  type: AUTH_SET_NEW_PASSWORD;
  password: string;
}
 
export const authSetNewPasswordAction: AuthSetNewPasswordAction = (
  password: string,
) => ({
  type: AUTH_SET_NEW_PASSWORD,
  password,
});
 
// Auth logout
export type AuthLogoutAction = () => IAuthLogoutActionResponse;
 
export interface IAuthLogoutActionResponse {
  type: AUTH_LOGOUT_USER;
}
 
export const authLogoutAction: AuthLogoutAction = () => ({
  type: AUTH_LOGOUT_USER,
});
 
// Set is loading
export type AuthSetIsLoadingAction = (
  isLoading: boolean,
) => IAuthSetIsLoadingActionResponse;
 
export interface IAuthSetIsLoadingActionResponse {
  type: AUTH_SET_IS_LOADING;
  isLoading: boolean;
}
 
export const authSetIsLoadingAction: AuthSetIsLoadingAction = (
  isLoading: boolean,
) => ({
  type: AUTH_SET_IS_LOADING,
  isLoading,
});
 
export type Action =
  | IAuthSetAuthStateActionResponse
  | IAuthSetAuthDataActionResponse
  | IAuthSignInActionResponse
  | IAuthSetNewPasswordActionResponse
  | IAuthLogoutActionResponse
  | IAuthSetIsLoadingActionResponse;