PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] JWT not working with cakephp

 March 15, 2022     cakephp-3.0, jwt, php     No comments   

Issue

i am trying to implement JWT Authentication to a CakePHP 3. i am following below tutorial:

http://www.bravo-kernel.com/2015/04/how-to-add-jwt-authentication-to-a-cakephp-3-rest-api/

i have completed basic setup and it's working good. but when i tried to register a user with the help of Postman it gave me following error:

Error: Call to a member function set() on boolean 
File /var/www/html/XXXXXX/vendor/friendsofcake/crud/src/Action/BaseAction.php 
Line: 196

my user controller code is:

public function add()
    {
        $this->Crud->on('afterSave', function(Event $event) {
            if ($event->subject->created) {
                $this->set('data', [
                    'id' => $event->subject->entity->id,
                    'token' => JWT::encode(
                        [
                            'sub' => $event->subject->entity->id,
                            'exp' =>  time() + 604800
                        ],
                    Security::salt())
                ]);
                $this->Crud->action()->config('serialize.data', 'data');
            }
        });
        return $this->Crud->execute();
    }

please help me


Solution

i just found the issue. i have created all templates with cake bake. so in this case i need add Flash to my components list on AppController.



Answered By - Rajinder
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing