@@ -51,7 +51,7 @@ import GHCJS.Foreign.Export (Export, export, derefExport)
5151import GHCJS.Foreign.Callback (Callback , syncCallback1 , OnBlocked (ContinueAsync ))
5252import GHCJS.Nullable (Nullable (.. ), nullableToMaybe , maybeToNullable )
5353import GHCJS.Types (JSVal , jsval )
54- import Happstack.Authenticate.Core (Email (.. ), User (.. ), Username (.. ), AuthenticateURL (AuthenticationMethods ), AuthenticationMethod (.. ), JSONResponse (.. ), Status (.. ), jsonOptions )
54+ import Happstack.Authenticate.Core (Email (.. ), User (.. ), Username (.. ), AuthenticateURL (AuthenticationMethods , Logout ), AuthenticationMethod (.. ), JSONResponse (.. ), Status (.. ), jsonOptions )
5555import qualified Happstack.Authenticate.Core as Authenticate
5656import Happstack.Authenticate.Password.Core (ChangePasswordData (.. ), UserPass (.. ), NewAccountData (.. ), ResetPasswordData (.. ), RequestResetPasswordData (.. ))
5757import Happstack.Authenticate.Password.URL (AccountURL (Password ), PasswordURL (Account , Token , PasswordRequestReset , PasswordReset ),passwordAuthenticationMethod )
@@ -569,7 +569,7 @@ logoutHandler routeFn update modelTV e =
569569 " logout" ->
570570 do debugStrLn $ " logoutHandler - logout"
571571 (Just d) <- GHCJS. currentDocument
572- clearUser modelTV
572+ clearUser routeFn modelTV
573573 _ ->
574574 do debugStrLn $ " unknown action - " ++ show action
575575 Nothing -> do debugStrLn " target is not an element"
@@ -877,8 +877,8 @@ setAuthenticateModel modelTV v =
877877 & isAdmin .~ (_uiAuthAdmin ui)
878878 updateAuthenticateModelFromToken modelTV (_uiToken ui)
879879
880- clearUser :: TVar AuthenticateModel -> IO ()
881- clearUser modelTV =
880+ clearUser :: ( AuthenticateURL -> Text ) -> TVar AuthenticateModel -> IO ()
881+ clearUser routeFn modelTV =
882882 do atomically $ modifyTVar' modelTV $ \ m ->
883883 m & usernamePasswordError .~ " "
884884 & muser .~ Nothing
@@ -887,7 +887,13 @@ clearUser modelTV =
887887 ls <- getLocalStorage w
888888 removeItem ls userKey
889889 (Just d) <- GHCJS. currentDocument
890- setCookie d (" atc=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT;" :: JSString )
890+
891+ -- We can't do this because the cookie must be httpOnly for security reasons
892+ -- setCookie d ("atc=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT;" :: JSString)
893+ -- So we have to make an API call so the server can set a new cookie
894+ xhr <- newXMLHttpRequest
895+ open xhr " POST" (routeFn Logout ) True
896+ send xhr
891897 doRedraws modelTV
892898
893899-- FIXME: what happens if this is called twice?
@@ -910,6 +916,8 @@ initHappstackAuthenticateClient baseURL sps =
910916 (Just v) -> do -- FIXME: check that atc exists an has same token value
911917 setAuthenticateModel modelTV v
912918
919+ let routeFn = (\ url -> baseURL <> toPathInfo url)
920+
913921 -- up-force-logout
914922 mForceLogouts <- getElementsByTagName d " up-force-logout"
915923 case mForceLogouts of
@@ -922,7 +930,7 @@ initHappstackAuthenticateClient baseURL sps =
922930 then debugStrLn " did not actually find up-force-logout"
923931 else do
924932 debugStrLn " up-force-logout"
925- clearUser modelTV
933+ clearUser routeFn modelTV
926934
927935 -- add login form handlers
928936 let attachLogin inline oldNode =
@@ -933,8 +941,8 @@ initHappstackAuthenticateClient baseURL sps =
933941 (Just inputUsername) <- getElementByNameAttr newElement " username"
934942 (Just inputPassword) <- getElementByNameAttr newElement " password"
935943 update =<< (atomically $ readTVar modelTV)
936- addEventListener newNode (ev @ Submit ) (loginHandler ( \ url -> baseURL <> toPathInfo url) inputUsername inputPassword update modelTV) False
937- addEventListener newNode (ev @ Click ) (logoutHandler ( \ url -> baseURL <> toPathInfo url) update modelTV) False
944+ addEventListener newNode (ev @ Submit ) (loginHandler routeFn inputUsername inputPassword update modelTV) False
945+ addEventListener newNode (ev @ Click ) (logoutHandler routeFn update modelTV) False
938946 pure update
939947 -- block login form
940948 mUpLogins <- getElementsByTagName d " up-login"
0 commit comments