Confusion over 'require login' behavior Quote from the {% requireLogin %} docs:


  This tag will ensure that the user is logged in. If they aren’t, they
  will be redirected to the Login page, and returned to the original
  page after successfully logging in.


Quote from the Login Form example in the docs:


  craft.session.returnUrl is set to the original URL that included the {% requireLogin %} tag that initiated the redirect to this login form. By default, users will be redirected based on your postLoginRedirect config setting value after logging in. 


That seems to be contradictory - the first sentence saying the return path will be the page that contained the requireLogin tag and the second saying the return path is defined by a config setting.

I want to be able to have the redirect go to the page that calls the login (I have 
 a few of them), but do not see a way of doing that. Using a return parameter in the login form does not work for obvious reasons. 

Am I missing something here? Any wisdom greatly appreciated!
By default Craft checks the postLoginRedirect setting in your config. Depending on this value the user is going to be redirected to certain place. But if there is a value in the user session that's set when the requireLogin function is called Yii2 will use this value instead. So the workflow is the following


Check for a session value, if there is one, redirect the user
Check for postLoginRedirect value, if there is one, redirect the user
Redirect to homepage



  Using a return parameter in the login form does not work for obvious reasons.


Could you explain those obvious reasons? Because I always use the returnUrl from UsersController when I create a login via ajax.

You don't have to do anything actually. Just include the Twig token and Yii2 will handle it