digiaonline/yii2-account

Rerurn url after login

Closed this issue · 2 comments

If you are locating on page /post/index and will try to call actions accesible only by authorized users for example /post/create - you will see login form.
After successful logging in you will be redirected on /post/index instead of going straight where you have tried to go.

It will be great to have configurable options for it. I see different ways to do it:

  1. Boolean option:
  • 'redirectToHomeAfterLogin' => true - user will be redirected to homepage;
  • 'redirectToHomeAfterLogin' => false - user navigation will be continued;
  1. Use preefined location aliases to redirect user after login:
  • 'redirectLocationAfterLogin' => 'home' - user will be redirected to homepage;
  • 'redirectLocationAfterLogin' => 'back' - user will be redirected to last visited page (current behavior);
  • 'redirectLocationAfterLogin' => 'forward' - user navigation will be continued;
  1. Define exact location to redirect user after login:
  • 'redirectLocationAfterLogin' => '/' - user will be redirected to homepage;
  • 'redirectLocationAfterLogin' => '/welcome' - user will be redirected to /welcome page;

// But in third case I don't know how to solve this issue.

On a future it will be great to have customizable return url for registration action too. Sometimes people need to send users to special ThankYou page. For afterRegistration only 3rd case is applicable.

I would say that this is working as intended. The plan was to let Yii handle login redirects, if it's not doing it correctly, then we have an issue.

I think the solution you proposed is overcomplicated, however I will consider giving the option to customize the URLs via module configuration.

EDIT: I have added support for configuring redirects through the whole module. It's currently only on develop but I'll merge it once I have tested it.

Thanks in advance! Keep up good work! :}