Member login and redirect to specific page

Silverstripe Version: 4

Question: I can see how you can change the redirection in SS 3 but there are no examples for SS 4

Basically we have the standard Member Login Form working but wish to redirect a non-admin user after login to a specific page. I have tried all sorts of things include Injections, extending MemberLoginForm but nothing seems to be recognised. What I mean by that is that no code I use does anything. I think everything I have been trying is SS3.

So - simply put - where / how do you redirect a user after login based on their group?

Thanks in advance

Try something like this

                <% if $CurrentMember %> 
                <br><a href="Security/logout">$CurrentMember.FirstName $CurrentMember.LastName Afmelden</a>
            <% else %> 
                <br><a href="Security/login?BackURL=home">Login</a>
            <% end_if %>

In LoingHandler.php there are a few lines like the following:

// If a default login dest has been set, redirect to that.
   $defaultLoginDest = Security::config()->get('default_login_dest');
   if ($defaultLoginDest) {
       return $this->redirect($defaultLoginDest);
   }

so in your yml config file, you can set the following:

Silverstripe\Security:
  - default_login_dest: '/account/index'
1 Like