Jump to content

Redirect on login to specific page


maddmac
 Share

Recommended Posts

Put this in your site/ready.php file:

$this->addHookAfter('Session::loginSuccess', null, function($event) {
    if($this->wire('user')->hasRole("target-role")) $this->wire('session')->redirect("other-url");
});

 

  • Like 12
  • Thanks 1
Link to comment
Share on other sites

4 minutes ago, BitPoet said:

Hook after ProcessLogin::afterLogin and there, if $this->user->roles has a match, do a $this->session->redirect().

 

24 minutes ago, adrian said:

Put this in your site/ready.php file:


$this->addHookAfter('Session::loginSuccess', null, function($event) {
    if($this->wire('user')->hasRole("target-role")) $this->wire('session')->redirect("other-url");
});

 

That did the trick. Thank you

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

I put the following code into our membership module but it does not seem to redirect. Any ideas why? Thanks.

    public function init() {
        parent::init();
        // set landing page
        $this->addHookAfter('Session::loginSuccess', null, function($event) {
            if (!$this->wire('user')->isSuperuser()) {
                $path = $this->wire('config')->urls->admin . "membership/";
                $this->wire('session')->redirect($path);
            }
        });        
    }
 

Link to comment
Share on other sites

2 hours ago, chcs said:

I put the following code into our membership module but it does not seem to redirect. Any ideas why? Thanks. 

Is your module autoload property set to true ?

if not, then set 'autoload' => true in the module info or if you want your module to be an autoload only on the admin area, then set autoload to : 'autoload' => function () { return (wire('page')->template == 'admin'); }

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...