[Vuejs]-Securing API EndPoints with JWT (JSON Web Token)

0👍

From Packege Documentation and a simple but good explaining tutorial I suggest you add

'storage' => 'Memory',
'checkAuthIn' => 'Controller.initialize',

in your $this->loadComponent(‘Auth’,…)

Also when you are creating token , add user-id, sub in payload like this

payload = ['id' => $user['id'],'sub' => $user['id'] ,'mail' => $data[0], 'password' => $data[1],'exp' =>  time() + 3600];

Also requesting you to follow the above tutorial link to understand better.

Edit: if this problem still exist, please

  • check whether Vue is sending the Token in API request

  • For debugging, Auth allow that method which is bind /holidays request to and check header by

    $header = $request->getHeaderLine(‘Authorization’);

  • print the $header in the controller method to see if CakePHP receives the Authorization Header.

Leave a comment