{"record":{"id":"cb501ef3f950bb62","repo":"discourse/discourse","slug":"invite-not-matching-email","errorCode":null,"errorMessage":"invite.not_matching_email","messagePattern":"invite\\.not_matching_email","errorType":"validation","errorClass":"ActiveRecord::RecordNotSaved","httpStatus":null,"severity":"warning","filePath":"app/models/invite_redeemer.rb","lineNumber":192,"sourceCode":"\n  private\n\n  def can_redeem_invite?\n    return false if !invite.redeemable?\n    return false if email.blank?\n\n    # Invite scoped to email has already been redeemed by anyone.\n    return false if invite.is_email_invite? && InvitedUser.exists?(invite_id: invite.id)\n\n    # The email will be present for either an invite link (where the user provides\n    # us the email manually) or for an invite scoped to an email, where we\n    # prefill the email and do not let the user modify it.\n    #\n    # Note that an invite link can also have a domain scope which must be checked.\n    email_to_check = redeeming_user&.email || email\n\n    if invite.email.present? && !invite.email_matches?(email_to_check)\n      raise ActiveRecord::RecordNotSaved.new(I18n.t(\"invite.not_matching_email\"))\n    end\n\n    if invite.domain.present? && !invite.domain_matches?(email_to_check)\n      raise ActiveRecord::RecordNotSaved.new(I18n.t(\"invite.domain_not_allowed\"))\n    end\n\n    # Anon user is trying to redeem an invitation, if an existing user already\n    # redeemed it then we cannot redeem now.\n    redeeming_user ||= User.where(admin: false, staged: false).find_by_email(email)\n    if redeeming_user.present? &&\n         InvitedUser.exists?(user_id: redeeming_user.id, invite_id: invite.id)\n      raise Invite::UserExists.new(I18n.t(\"invite.existing_user_already_redemeed\"))\n    end\n\n    true\n  end\n\n  # Note that the invited_user is returned by #redeemed, so other places","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/discourse/discourse/blob/1b2d7253e854205d2c95c80b2c6a1cdd42e45059/app/models/invite_redeemer.rb#L174-L210","documentation":"InviteRedeemer#can_redeem_invite? raises RecordNotSaved with invite.not_matching_email when the invite was issued to a specific email but the redeeming user's email (or supplied email) does not match per invite.email_matches?.","triggerScenarios":"Redeeming an emailed invite link with a different account, or passing an email query param that differs from the invited address.","commonSituations":"User forwards an invite to a colleague; redeems while logged in as another account; typo in the email param.","solutions":["Redeem the invite with the exact email it was sent to (or logged out so the email field applies)","Ask the inviter to generate a new invite for the new address","For broad invites, invite by domain instead of a fixed email"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"email_to_check = current_user&.email || params[:email]\nreturn mismatch_page if invite.email.present? && !invite.email_matches?(email_to_check)","typeGuard":null,"tryCatchPattern":"rescue ActiveRecord::RecordNotSaved => e; show invite.not_matching_email message","preventionTips":["Prefer unrestricted multi-use invites when recipients are unknown","Show the invited email as read-only during redemption"],"tags":["discourse","invites","email-mismatch"],"backgroundTag":"invite-email-mismatch","analyzedSha":"1b2d7253e854205d2c95c80b2c6a1cdd42e45059","analyzedAt":"2026-08-26T03:11:08.302Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}