How can I redirect to a certain page after signing in using the latest Rainlab User plugin?

Hi All,

With an earlier version of the RainLab User plugin I used to be able to simply add a directive to my sign in page for redirecting e.g.:

[account]
redirect = "services"

This seems to be gone now on the latest version. I have tried adding the account component and putting the redirect manually to no avail.

I also tried overriding the onLogin function but I’m not sure I’m doing that correctly e.g.:

function onLogin() {
    return Redirect::to('/services');
}

I am on October CMS build 4.1.13 and RainLab User plugin version 3.3.1.

Any pointers gratefully appreciated, thanks.

Hi

have to tried to add an hidden input field called redirect with your value ?

Hi Chris,

Thank you for your reply.

I’m just using the authentication, session and account components on my sign in page so I don’t have direct access to the form HTML to be able to add an extra input field.

I was hoping to get it working just using the plug-in configuration itself rather than having to make manual changes myself.

I hope this makes sense. Thanks for your suggestion

Hi @Call2call

With the PHP you could do

function onLogin() {
    $this->account->onLogin();
    return Redirect::to('/services');
}

Hi @daftspunk,

Thanks for the code (I was wondering how the onLogin override worked from the plugin documentation).

It gave this error when I tried it though:

The component 'RainLab\User\Components\Account' does not contain a method 'onLogin'. {"exception":[]}

After a bit of head scratching, I noticed the method is in the Authentication component so I tried this and it worked:

<?php

function onLogin() {
    $this->authentication->onLogin();
    
    return Redirect::to('/services');
}

So it looks like I needed to override the Authentication onLogin method.

Thanks for pointing me in the right direction.

2 Likes