wire-server icon indicating copy to clipboard operation
wire-server copied to clipboard

User subsystems: update identity

Open fisx opened this issue 1 year ago • 2 comments

WPB-8881

Checklist

  • [ ] Add a new entry in an appropriate subdirectory of changelog.d
  • [ ] Read and follow the PR guidelines

fisx avatar Jul 26 '24 12:07 fisx

a610321 is interesting:

validateTokens ::
  (ZAuth.TokenPair u a) =>
  List1 (ZAuth.Token u) ->
  Maybe (ZAuth.Token a) ->
  ExceptT ZAuth.Failure (AppT r) (UserId, Cookie (ZAuth.Token u))
validateTokens uts at = do
  tokens <- forM uts $ \ut -> lift $ runExceptT (validateToken ut at)
  getFirstSuccessOrFirstFail tokens
  where
    -- FUTUREWORK: There is surely a better way to do this
    getFirstSuccessOrFirstFail ::
      (Monad m) =>
      List1 (Either ZAuth.Failure (UserId, Cookie (ZAuth.Token u))) ->
      ExceptT ZAuth.Failure m (UserId, Cookie (ZAuth.Token u))
    getFirstSuccessOrFirstFail tks = case (lefts $ NE.toList $ List1.toNonEmpty tks, rights $ NE.toList $ List1.toNonEmpty tks) of
      (_, suc : _) -> pure suc
      (e : _, _) -> throwE e
      _ -> throwE ZAuth.Invalid -- Impossible

turned into this:

validateTokens ::
  forall u a v.
  (v ~ (UserId, Cookie (ZAuth.Token u))) =>
  (ZAuthWrapper.TokenPair u a) =>
  List1 (ZAuth.Token u) ->
  Maybe (ZAuth.Token a) ->
  Either ZAuthWrapper.Failure v
validateTokens uts at = ((`validateToken` at) `mapM` uts) & second List1.head

but

fisx avatar Jul 26 '24 19:07 fisx

also i'm a little proud of my commit discipline today! :)

fisx avatar Jul 26 '24 19:07 fisx