import * as validator from "validator" ; import { UserAuth } from "../custom-types" ; import { DEFAULT_USER_AUTH } from "./Consts" ; param email param password param setError export const validateLoginForm = ( email , password , setError ) : boolean => { if ( ! email || ! password ) { setError ( "Please enter a valid email and password." ) ; return false ; } if ( ! validator . isEmail ( email ) ) { setError ( "Please enter a valid email address." ) ; return false ; } return true ; } ; /** Return user auth from local storage value */ export const getStoredUserAuth = ( ) : UserAuth => { const auth = window . localStorage . getItem ( "UserAuth" ) ; if ( auth ) { return JSON . parse ( auth ) ; } return DEFAULT_USER_AUTH ; } ; param url param method param bodyParams export const apiRequest = async ( url , method , bodyParams ? ) : Promise < any > => { const response = await fetch ( url , { method , headers : { Accept : "application/json" , "Content-Type" : "application/json" } , body : bodyParams ? JSON . stringify ( bodyParams ) : undefined } ) ; return await response . json ( ) ; } ;