Automatically re-authenticate to authd on page reload.

This commit is contained in:
Philippe Pittoli 2024-02-18 02:06:17 +01:00
parent 0f0d016ad7
commit d84c5f789a

View File

@ -343,6 +343,13 @@ handleAction = case _ of
WS.WSJustConnected -> do
H.tell _ai unit AI.ConnectionIsUp
H.tell _aai unit AAI.ConnectionIsUp
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage
case token of
Nothing -> handleAction $ Log $ SimpleLog "no token!"
Just t -> do
handleAction $ Log $ SimpleLog "Let's authenticate to authd"
handleAction $ AuthenticateToAuthd (Left t)
WS.WSJustClosed -> do
H.tell _ai unit AI.ConnectionIsDown
@ -451,13 +458,13 @@ handleAction = case _ of
AuthenticateToAuthd v -> case v of
Left token -> do
-- TODO: currently, there is no message to send to `authd` to authenticate a user only with a token.
handleAction $ Log $ SimpleLog $ "Trying to login with token: " <> token
handleAction $ Log $ SimpleLog "[🤖] authenticate to authd with a token!"
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkAuthByToken { token }
H.tell _ws_auth unit (WS.ToSend message)
Right (Tuple login password) -> do
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkLogin { login, password }
H.tell _ws_auth unit (WS.ToSend message)
-- | Send a received authentication daemon message `AuthD.AnswerMessage` to a component.
DispatchAuthDaemonMessage message -> do
{ current_page } <- H.get