Call to 'anvil.users.login_with_form(...)' never returns when a valid eMail address is submitted

Hello Friends:

Let me follow-up my question yesterday with a trivial use-case involving it.

Let’ say the following snippet is for the simplest of Landing Pages, one only with a Button component labeled Login (as depicted).

Screenshot from 2022-07-20 13-22-26

Landing Page Form code:

class LandingForm(LandingFormTemplate):
  def __init__(self, **properties):
      self.init_components(**properties)

  # 'Click' Event handler for Login button.
  def btn_login_click(self, **event_args):
      if not anvil.users.login_with_form(allow_cancel=True,allow_remembered=False):
          print('Path-A') # User clicked Cancel button.
      else:
          print('Path-B') # This is never reached under any circumstance.
          self.textbox_hello_world.visible = True

Now, as long as the user submits invalid eMail addresses, login_with_form(...) loops internally forever. The only way out is either to (A) click the login form’s Cancel button and Path-A is executed; or (B) submit a valid eMail address and (to my surprise) Path-B is not executed. In fact, Path-B is never executed because login_with_form(...) vectors off somewhere else.

In this trivial example, a TextBox with Hello, World! is made visible on success, but practical cases might perform, say, additional user-validation logic, or navigate to a specific App based on that logic.

@anvil

How can one perform such if/else conditional logic if Path-B can never execute?

Thank you!

You’re using the magic link login method, so the behavior makes sense. When the user elects to login via a magic link, they get a message saying, basically, “You’re done here, close this window”.

When they click the link in their email, the app opens again. Presumably the app should use anvil.users.get_user() to see if the user is logged in to do the part that you have in your else.

1 Like

@jshaffstall Thank you. I’ve been refactoring (my Landing Page to App Page and back login/logout-sequencing) because of the observed behaviors. Until you described the lifecycle just now, things weren’t clear, but is certainly now. Indeed: The user basically kills the current instance (by closing the tab as instructed) and open a new one when they click the Magic Link. It all makes sense now. Thank you!

1 Like