Skip to content

Commit 6a5a492

Browse files
committed
fix -fDebug flag. minor tweaks for turnstile
1 parent da5183e commit 6a5a492

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

happstack-authenticate.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Library
6161
ghc-options: -Werror=incomplete-patterns
6262
hs-source-dirs: src
6363
if flag(Debug)
64-
cpp-options: "-DDEBUG_CLIENT"
64+
cpp-options: "-DDEBUG"
6565

6666
Exposed-modules:
6767
Happstack.Authenticate.Core
@@ -132,6 +132,8 @@ Library
132132

133133
executable happstack-authenticate-client
134134
import: shared-ghcjs-properties
135+
if flag(Debug)
136+
cpp-options: "-DDEBUG"
135137
if impl(ghcjs)
136138
buildable: True
137139
else

src/Happstack/Authenticate/Client.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
{-# LANGUAGE TypeOperators #-}
1414
module Happstack.Authenticate.Client where
1515

16+
import Control.Monad.Reader (ask)
1617
import Control.Monad.Trans (MonadIO(liftIO))
1718
import Control.Concurrent (threadDelay)
1819
import Control.Concurrent.STM.TVar (TVar, newTVarIO, modifyTVar', readTVar, writeTVar)
1920
import Control.Concurrent.STM (atomically)
2021
import Control.Lens ((&), (.~))
2122
import Control.Lens.TH (makeLenses)
22-
import Chili.Types (Event(Change, ReadyStateChange, Submit), EventObject, InputEvent(Input), InputEventObject(..), IsJSNode, JSElement, JSNode, JSNodeList, StorageEvent(Storage), StorageEventObject, XMLHttpRequest, byteStringToArrayBuffer, createJSElement, ev, getData, getLength, item, key, unJSNode, fromJSNode, getChecked, getFirstChild, getOuterHTML, getValue, newXMLHttpRequest, nodeType, nodeValue, oldValue, open, preventDefault, querySelector, send, sendString, getOuterHTML, getStatus, getReadyState, getResponseByteString, getResponse, getResponseText, getResponseType, item, newValue, nodeListLength, parentNode, replaceChild, remove, sendArrayBuffer, setProperty, setRequestHeader, setResponseType, setTextContent, stopPropagation, toJSNode, url, window)
23+
import Chili.Types (Event(Change, ReadyStateChange, Submit), EventObject, InputEvent(Input), InputEventObject(..), IsJSNode, JSElement, JSNode, JSNodeList, ResourceEvent(Load), StorageEvent(Storage), StorageEventObject, XMLHttpRequest, byteStringToArrayBuffer, createJSElement, ev, getData, getLength, item, key, unJSNode, fromJSNode, getChecked, getFirstChild, getOuterHTML, getValue, newXMLHttpRequest, nodeType, nodeValue, oldValue, open, preventDefault, querySelector, send, sendString, getOuterHTML, getStatus, getReadyState, getResponseByteString, getResponse, getResponseText, getResponseType, item, newValue, nodeListLength, parentNode, replaceChild, remove, sendArrayBuffer, setProperty, setRequestHeader, setResponseType, setTextContent, stopPropagation, toJSNode, url, window)
2324
import qualified Chili.Types as Chili
2425
import qualified Data.Aeson as Aeson
2526
import qualified Data.Aeson.Text as Aeson
@@ -57,19 +58,27 @@ import Happstack.Authenticate.Password.Core(ChangePasswordData(..), UserPass(..)
5758
import Happstack.Authenticate.Password.URL(AccountURL(Password), PasswordURL(Account, Token, PasswordRequestReset, PasswordReset),passwordAuthenticationMethod)
5859
import GHC.Generics (Generic)
5960
import GHCJS.DOM.Document (setCookie)
61+
import GHCJS.DOM.EventM (EventName, EventM)
62+
import qualified GHCJS.DOM.EventM as EventM
63+
import qualified GHCJS.DOM.GlobalEventHandlers as DOM (load)
6064
import GHCJS.DOM.Location (Location, getSearch, setHref)
6165
import qualified GHCJS.DOM.URLSearchParams as Search
6266
import GHCJS.DOM.Window (getLocalStorage, getLocation)
6367
import GHCJS.DOM.Storage (Storage, getItem, removeItem, setItem)
6468
import GHCJS.DOM.StorageEvent (StorageEvent)
6569
import qualified GHCJS.DOM.StorageEvent as StoragEvent
6670
import qualified GHCJS.DOM as GHCJS
71+
import qualified GHCJS.DOM.Types as DOM
6772
import System.IO (hFlush, stdout, hGetBuffering, hSetBuffering, BufferMode(..))
6873
import Text.Shakespeare.I18N (Lang, mkMessageFor, renderMessage)
6974
import Unsafe.Coerce (unsafeCoerce)
7075

7176
import Web.Routes (RouteT(..), toPathInfo, toPathSegments)
7277

78+
79+
on :: (DOM.IsEvent e, DOM.IsEventTarget t) => t -> EventName t e -> (e -> IO ()) -> IO (IO ())
80+
on elem eventName handler = EventM.on elem eventName (do e <- ask ; liftIO (handler e))
81+
7382
debugPrint :: Show a => a -> IO ()
7483

7584
#ifdef DEBUG
@@ -989,10 +998,13 @@ initHappstackAuthenticateClient baseURL mTurnstileKey sps =
989998
atomically $ modifyTVar' modelTV $ \m -> m { _turnstileToken = Just (textFromJSString token) }
990999

9911000
case mTurnstileKey of
992-
Nothing -> pure ()
1001+
Nothing ->
1002+
do debugStrLn "turnstile not enabled because no turnskile key was found."
9931003
(Just siteKey) ->
9941004
do tId <- turnstileRender "#cf-turnstile-widget" siteKey addTurnstileToken
1005+
debugStrLn "called turnstileRender"
9951006
pure ()
1007+
9961008
pure update
9971009
-- addEventListener newNode (ev @Click) (logoutHandler (\url -> baseURL <> toPathInfo url) update modelTV) False
9981010
-- listen for changes to local storage

0 commit comments

Comments
 (0)