summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-11-18 05:51:04 -0500
committerLLLL Colonq <llll@colonq>2024-11-18 05:51:04 -0500
commit229bbf710df29809b7fe0068c45d2c47a1908598 (patch)
treecb0b756a5e4fec5dc7dbf3e1fb86742ded5794ab
parentee790dfbe80ef1b8f7540334308025fc618bb659 (diff)
Fix logout
-rw-r--r--src/Auth.js10
-rw-r--r--src/Auth.purs4
-rw-r--r--src/Main.purs23
3 files changed, 12 insertions, 25 deletions
diff --git a/src/Auth.js b/src/Auth.js
index 3c50658..d9c21df 100644
--- a/src/Auth.js
+++ b/src/Auth.js
@@ -45,16 +45,6 @@ export const _getToken = (Just) => (Nothing) => (pair) => () => {
return Nothing;
};
-export const _getSessionCookie = (Just) => (Nothing) => () => {
- let cookie = null;
- for (let c of document.cookie.split("; ")) {
- const [k, v] = c.split("=");
- if (k === "authelia_session") cookie = v;
- }
- if (cookie) return Just(cookie);
- return Nothing;
-};
-
export const _clearSessionCookie = () => {
document.cookie = "authelia_session=; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=None; Secure";
};
diff --git a/src/Auth.purs b/src/Auth.purs
index 2a87b6a..7f87f83 100644
--- a/src/Auth.purs
+++ b/src/Auth.purs
@@ -28,10 +28,6 @@ authHeader (Tuple t n) =
, "\""
]
-foreign import _getSessionCookie :: forall a. (a -> Maybe a) -> Maybe a -> Effect (Maybe String)
-getSessionCookie :: forall m. MonadEffect m => m (Maybe String)
-getSessionCookie = liftEffect $ _getSessionCookie Just Nothing
-
foreign import _clearSessionCookie :: Effect Unit
clearSessionCookie :: forall m. MonadEffect m => m Unit
clearSessionCookie = liftEffect _clearSessionCookie
diff --git a/src/Main.purs b/src/Main.purs
index bd9288e..e286a24 100644
--- a/src/Main.purs
+++ b/src/Main.purs
@@ -3,7 +3,7 @@ module Main where
import Prelude
import Audio as Audio
-import Auth (AuthInfo, authHeader, getToken, startTwitchAuth, getSessionCookie, clearSessionCookie)
+import Auth (AuthInfo, authHeader, getToken, startTwitchAuth, clearSessionCookie)
import Config as Config
import Data.String as String
import Data.Array (head)
@@ -232,8 +232,16 @@ mainMenu = launchAff_ do
mainAuth :: Effect Unit
mainAuth = launchAff_ do
liftEffect $ log "hello from auth"
- getSessionCookie >>= case _ of
- Nothing -> do
+ { status } <- fetch "https://secure.colonq.computer/api/status" {}
+ case status of
+ 200 -> do
+ container <- byId "lcolonq-auth-logout"
+ removeClass "lcolonq-invisible" container
+ logout <- byId "lcolonq-auth-logout-link"
+ listen logout "click" \_ev -> do
+ clearSessionCookie
+ UI.reload
+ _ -> do
container <- byId "lcolonq-auth-login"
removeClass "lcolonq-invisible" container
form <- byId "lcolonq-auth-form"
@@ -243,20 +251,13 @@ mainAuth = launchAff_ do
passwordInp <- byId "lcolonq-auth-password"
username <- getValue usernameInp
password <- getValue passwordInp
- { text: resp } <- fetch ("/api/firstfactor")
+ { text: resp } <- fetch "/api/firstfactor"
{ method: POST
, headers: { "Content-Type": "application/json" }
, body: UI.toJSON { username, password }
}
res <- resp
liftEffect $ log res
- Just _ -> do
- container <- byId "lcolonq-auth-logout"
- removeClass "lcolonq-invisible" container
- logout <- byId "lcolonq-auth-logout-link"
- listen logout "click" \_ev -> do
- clearSessionCookie
- UI.reload
main :: Effect Unit
main = case Config.mode of