Invite link invalidated by attempt to use it while logged in

Description

Original report: https://github.com/mattermost/mattermost-server/issues/11903

Summary
This is not a regression.
Following an invite link while logged in as another user invalidates the link but doesn't allow the new user to sign up.

Steps to reproduce
1. Enable email invitations (System Console > Authentication > Signup > Enable Email Invitations).
2. Invite someone by email (switch to team, Burger Menu > Send Email Invite) (e.g. invite yourself via another email not yet known to Mattermost).
3. Click on the link in the invitation email while logged in as another user.

Expected behavior
Either it should be possible to sign up as the new user despite already being logged in; or, if not, there should be a message saying that signup only works when you're not logged in; most importantly, in the latter case, the invitation link shouldn't be invalidated by this failed attempt.

Observed behavior
The link doesn't lead to the signup page but to the normal user interface for the user who's already logged in; there's no indication of a failed signup attempt. If you now log out and try to use the invitation link again, it doesn't work anymore (though this only becomes apparent after you've filled in the form and try to submit it). A look at the database confirms that the invitation token is deleted on the first attempt.

QA Test Steps

None

Status

Mana

None

Assignee

Katie Wiersgalla

Reporter

Amy Blais

Epic Link

Fix versions

Mattermost Team

Platform

Sprint

None

Labels

GitHub Issue

None