1- import axios from " axios" ;
2- import { Dispatch } from " redux" ;
3- import Constants from " ../constants" ;
4- import { ActionAuthTypes , ActionMessagesTypes } from ". /types" ;
1+ import axios from ' axios' ;
2+ import { Dispatch } from ' redux' ;
3+ import Constants from ' ../constants' ;
4+ import { ActionAuthTypes , ActionMessagesTypes } from 'actions /types' ;
55
66export const tokenHeader = ( ) : { headers : { Authorization : string } } => {
7- const token = localStorage . getItem ( " _wp_react_typescipt_token" ) ;
7+ const token = localStorage . getItem ( ' _wp_react_typescipt_token' ) ;
88 return { headers : { Authorization : `Bearer ${ token } ` } } ;
99} ;
1010
@@ -37,11 +37,11 @@ export const authUser: AuthUserType = (credentials, callback) => {
3737 dispatch < ClearMessageAction > ( { type : ActionMessagesTypes . clearMsg } ) ;
3838 const response = await axios . post ( `${ Constants . jwtAuthUri } ` , credentials ) ;
3939 dispatch < AuthUserAction > ( { type : ActionAuthTypes . authUser } ) ;
40- localStorage . setItem ( " _wp_react_typescipt_token" , response . data . token ) ;
40+ localStorage . setItem ( ' _wp_react_typescipt_token' , response . data . token ) ;
4141 } catch ( error ) {
4242 dispatch < WarningMessageAction > ( {
4343 type : ActionMessagesTypes . warningMsg ,
44- payload : " Incorrect username or password"
44+ payload : ' Incorrect username or password'
4545 } ) ;
4646 }
4747 callback ( ) ;
@@ -58,13 +58,17 @@ export interface SuccessMessageAction {
5858}
5959
6060export const unAuthUser = ( ) => {
61- localStorage . removeItem ( " _wp_react_typescipt_token" ) ;
61+ localStorage . removeItem ( ' _wp_react_typescipt_token' ) ;
6262 return ( dispatch : Dispatch ) => {
6363 dispatch < UnAuthUserAction > ( { type : ActionAuthTypes . unAuthUser } ) ;
6464 dispatch < ClearMessageAction > ( { type : ActionMessagesTypes . clearMsg } ) ;
6565 dispatch < SuccessMessageAction > ( {
6666 type : ActionMessagesTypes . successMsg ,
67- payload : " Thanks for trying the app!"
67+ payload : ' Thanks for trying the app!'
6868 } ) ;
6969 } ;
7070} ;
71+
72+ export interface TestingAuthAction {
73+ type : ActionAuthTypes . forTesting ;
74+ }
0 commit comments