I need some help with my login process, it's working but I feel it's not the best approach to achieve it
I have the following workflow for the Login process :
1- enter username/password -> press login
2- check for a cookie id if this is a new device/browser verify the user's phone number.
3- after verifying -> redirect to the login page to enter credentials again and continue login.
My module code :
1- VerifySMS controller: I'm saving a unique cookie to identify the user device later.
2- inside module init()
Event::on(
User::class,
User::EVENT_BEFORE_AUTHENTICATE,
function (AuthenticateUserEvent $event) {
$newDevice = "check if it's new device using cookies";
if ($newDevice) {
$event->sender->authError = "Error";
Craft::$app->getResponse()->redirect('to verify phone number controller');
}
}
);
Right now I'm checking for a new device before authenticating and i need to repeat the login again after I verify the number.
I need to do it like this:
First validating username/password --> if True then check for a new device --> if True then verify the phone number and after this proceed with the login directly to the home page(authenticate) without needing to require username/pass again ??
I hope that I explained it clear enough.
Thank you all