1- import { createRequestActionTypes , createApiRequest } from '../utils' ;
2- import '../../services/api' ;
1+ import type { Reducer } from 'redux' ;
2+
3+ import '../../../services/api' ;
4+ import { createRequestActionTypes , createApiRequest } from '../../utils' ;
5+
6+ import type { AuthenticationAction , AuthenticationState } from './types' ;
37
48export const SET_UNAUTHENTICATED = createRequestActionTypes (
59 'authentication' ,
@@ -11,16 +15,19 @@ export const FETCH_USER = createRequestActionTypes('authentication', 'FETCH_USER
1115const initialState = {
1216 isAuthenticated : true ,
1317 user : '' ,
14- error : '' ,
18+ error : undefined ,
1519} ;
1620
17- const authentication = function ( state = initialState , action ) {
21+ const authentication : Reducer < AuthenticationState , AuthenticationAction > = (
22+ state = initialState ,
23+ action ,
24+ ) => {
1825 switch ( action . type ) {
1926 case SET_UNAUTHENTICATED . SUCCESS : {
20- return { ...state , isAuthenticated : false , user : '' , error : '' } ;
27+ return { ...state , isAuthenticated : false , user : '' , error : undefined } ;
2128 }
2229 case SET_AUTHENTICATED . SUCCESS : {
23- return { ...state , isAuthenticated : true , error : '' } ;
30+ return { ...state , isAuthenticated : true , error : undefined } ;
2431 }
2532 case SET_AUTHENTICATED . FAILURE : {
2633 return { ...state , error : action . error } ;
@@ -34,7 +41,7 @@ const authentication = function (state = initialState, action) {
3441 }
3542} ;
3643
37- export const authenticate = ( user , password ) => {
44+ export const authenticate = ( user : string , password : string ) => {
3845 return createApiRequest ( {
3946 request : window . api . authenticate ( user , password ) ,
4047 actions : SET_AUTHENTICATED ,
0 commit comments