Automatically re-authenticate to authd on page reload.

beta
Philippe Pittoli 2024-02-18 02:06:17 +01:00
parent 0f0d016ad7
commit d84c5f789a
1 changed files with 10 additions and 3 deletions

View File

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