From e3ac2174241a0b2cbd0e1f130e277cca13d2f2c9 Mon Sep 17 00:00:00 2001 From: Livio Spring Date: Mon, 9 Oct 2023 10:26:27 +0300 Subject: [PATCH] fix: ensure no events are skipped on token check (#6663) fix: ensure no events are skipped on token check --- .../eventsourcing/eventstore/token_verifier.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal/authz/repository/eventsourcing/eventstore/token_verifier.go b/internal/authz/repository/eventsourcing/eventstore/token_verifier.go index 9524958ba1..f8ca3bf76d 100644 --- a/internal/authz/repository/eventsourcing/eventstore/token_verifier.go +++ b/internal/authz/repository/eventsourcing/eventstore/token_verifier.go @@ -45,16 +45,19 @@ func (repo *TokenVerifierRepo) tokenByID(ctx context.Context, tokenID, userID st defer func() { span.EndWithError(err) }() instanceID := authz.GetInstance(ctx).InstanceID() + + // always load the latest sequence first, so in case the token was not found by id, + // the sequence will be equal or lower than the actual projection and no events are lost + sequence, err := repo.View.GetLatestTokenSequence(ctx, instanceID) + logging.WithFields("instanceID", instanceID, "userID", userID, "tokenID", tokenID). + OnError(err). + Errorf("could not get current sequence for token check") + token, viewErr := repo.View.TokenByIDs(tokenID, userID, instanceID) if viewErr != nil && !caos_errs.IsNotFound(viewErr) { return nil, viewErr } if caos_errs.IsNotFound(viewErr) { - sequence, err := repo.View.GetLatestTokenSequence(ctx, instanceID) - logging.WithFields("instanceID", instanceID, "userID", userID, "tokenID", tokenID). - OnError(err). - Errorf("could not get current sequence for token check") - token = new(model.TokenView) token.ID = tokenID token.UserID = userID