Session Probem?

I follow the all docs as mention cakephp 4
Case 1. when I check role based login . So check the role after authentication code

$result = $this->Authentication->getResult(); 
    if ($result->isValid()) { 
        $user = $result->getData();
                if($user['role_id'] == 2){

2.but when admin credentials then works well got an error, but i refresh the page the session automatically set. and then user credentials enter then already the session set by when i refresh the page
what’s i doing wrong in the code Please any suggestion about thre cakePHP 4.0
3. I already worked on cakephp 3.8 it’s works on the role based login.


unfortunately it is not possible to see in which action you are using your code.
As far as I know $this->Authentication->getResult() is called within an action that should do a “login”.
After that you usually make a redirect to an action the user may have called before (referrer) - the user (no matter with which role) was successfully authenticated.
The user authorization (is the authenticated user allowed to do what he wants = call action or …) happens in CakePHP4 in (the new) policy classes. There a role based authorization should take place.
See Checking Authorization - 2.x

I recommend you to watch the following workshop videos from CakeFest 2020 too:

Thanks for Repay I will check it. :innocent: