Closed AbidMuhammadTaufiq closed 2 years ago
Hi @L200180059 . Your question is a little bit confusing. Is your question about Myth:Auth's filters usage or it's about after successful authentication process ability to redirect to different views according by users roles?
And the recommended place to ask questions about how to use the lib is to open new discussion.
Hi @L200180059 .
Your question is a little bit confusing. Is your question about Myth:Auth's filters usage or it's about after successful authentication process ability to redirect to different views according by users roles?
My point is about after succesful authentication process ability to redirect to different views according by users roles (point 2)
Ok. In that case the quick way to do it is modifying AuthController's attemptLogin() method. Example code:
public function attemptLogin()
{
// default code goes here ...
// Is the user being forced to reset their password?
if ($this->auth->user()->force_pass_reset === true) {
return redirect()->to(route_to('reset-password') . '?token=' . $this->auth->user()->reset_hash)->withCookies();
}
// add logic to manage different views
$authorization = service('authorization');
if ($authorization->inGroup('admin', $this->auth->id())) {
$whereToGo = route_to('admin_dashboard');
} elseif ($authorization->inGroup('reguler_users', $this->auth->id())) {
$whereToGo = route_to('user_dashbord');
} else {
$whereToGo = route_to('default_home');
}
$redirectURL = session('redirect_url') ?? $whereToGo;;
unset($_SESSION['redirect_url']);
// end of logic to manage different views code
return redirect()->to($redirectURL)->withCookies()->with('message', lang('Auth.loginSuccess'));
}
The best way to modify AuthController is to extend it to your app/controllers folder. And don't forget to change login routes to reflect changes.
It looks like this became a Discussion; can this Issue close?
Yes, moved to discussions.
Yes sure
I want to ask about the login filter by role, how do I make each role can have different direct view?. thank you