fix: /logout routes; improved error handling for invites

This commit is contained in:
2026-09-01 15:28:18 +02:00
parent 4b703b077c
commit b35dc4841f
6 changed files with 35 additions and 4 deletions
+11 -2
View File
@@ -33,13 +33,22 @@ func (r *InviteRepo) CreateInvite(ctx context.Context, inviterUserID string, cod
}
func (r *InviteRepo) DeleteInvite(ctx context.Context, userID string, inviteID string) error {
_, err := r.conn(ctx).ExecContext(ctx,
res, err := r.conn(ctx).ExecContext(ctx,
"DELETE FROM invites WHERE id = $1 AND inviter_user_id = $2 AND consumed_at IS NULL",
inviteID, userID,
)
if err != nil {
return fmt.Errorf("failed to delete invite: %w", err)
}
affected, err := res.RowsAffected()
if err != nil {
return fmt.Errorf("could not get rows affected: %w", err)
}
if affected < 1 {
// It's more of an assumption,
// but unless I encounter this being wrong, I'll keep it.
return domain.ErrInviteConsumed
}
return nil
}
@@ -57,7 +66,7 @@ func (r *InviteRepo) ConsumeInvite(ctx context.Context, inviteID string, invitee
return fmt.Errorf("could not get rows affected: %w", err)
}
if affected < 1 {
return fmt.Errorf("invite not found or expired")
return domain.ErrInviteInvalid
}
return nil