@@ -171,7 +171,7 @@ module App =
171171
172172 { model with
173173 Auth = Identified(id, Online token)
174− Page = Conversations
174+ Page = match model.Page with Setup -> Conversations | p -> p
175175 Error = None
176176 PollStatus = "polling..."
177177 FlushingOutbox = true },
@@ -185,6 +185,14 @@ module App =
185185 PollRetries = 0 },
186186 []
187187
188+ | TokenExpired ->
189+ match model.Auth with
190+ | Identified(id, Online _) ->
191+ let m = setConn Connecting model
192+ { m with FlushingOutbox = false; PollRetries = 0 },
193+ [ CmdConnect(model.ServerUrl, id) ]
194+ | _ -> model, []
195+
188196 | DoDisconnect ->
189197 { setConn Offline model with
190198 PollStatus = ""
@@ -482,6 +490,9 @@ module App =
482490 do! Store.dequeueOutbox item.Id
483491 dispatch (FlushResult true)
484492 with
493+ | Unauthorized ->
494+ log "outbox unauthorized, reauthenticating"
495+ dispatch TokenExpired
485496 | ServerRejected msg ->
486497 log $"outbox rejected, dropping: {msg}"
487498 do! Store.dequeueOutbox item.Id
@@ -503,6 +514,11 @@ module App =
503514 let! response = poll session.Url session.Token cursor
504515 log $"poll response: {response.Events.Length} events, cursor={response.Cursor}"
505516
517+ if not response.Authorized then
518+ log "poll unauthorized, reauthenticating"
519+ dispatch TokenExpired
520+ else
521+
506522 let ackIds = response.Events |> Array.map _.Id |> Array.toList
507523
508524 let results =