edenspiekermann / craft-jwt-auth

Enable authentication to Craft through the use of Javascript Web Tokens (JWT)
MIT License
5 stars 16 forks source link

🐞 Local server = crash on start #11

Open rtrudel opened 5 years ago

rtrudel commented 5 years ago

Describe the bug When I re-serve my Craft app, I get this error:

$ ./craft serve 
Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: craft\console\Request::headers'

in /path/to/craft/vendor/yiisoft/yii2/base/Component.php:154

Stack trace:
#0 /path/to/craft/vendor/edenspiekermann/craft-jwt-auth/src/services/JWT.php(40): yii\base\Component->__get('headers')
#1 /path/to/craft/vendor/edenspiekermann/craft-jwt-auth/src/CraftJwtAuth.php(62): edenspiekermann\craftjwtauth\services\JWT->getJWTFromRequest()
#2 [internal function]: edenspiekermann\craftjwtauth\CraftJwtAuth->edenspiekermann\craftjwtauth\{closure}(Object(yii\base\Event))
#3 /path/to/craft/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Object(Closure), Object(yii\base\Event))
#4 /path/to/craft/vendor/craftcms/cms/src/base/ApplicationTrait.php(1360): yii\base\Component->trigger('init')
#5 /path/to/craft/vendor/craftcms/cms/src/console/Application.php(65): craft\console\Application->_postInit()
#6 /path/to/craft/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\console\Application->init()
#7 /path/to/craft/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->__construct(Array)
#8 /path/to/craft/vendor/yiisoft/yii2/console/Application.php(89): yii\base\Application->__construct(Array)
#9 /path/to/craft/vendor/craftcms/cms/src/console/Application.php(54): yii\console\Application->__construct(Array)
#10 [internal function]: craft\console\Application->__construct(Array)
#11 /path/to/craft/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array)
#12 /path/to/craft/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('craft\\console\\A...', Array, Array)
#13 /path/to/craft/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('craft\\console\\A...', Array, Array)
#14 /path/to/craft/vendor/craftcms/cms/bootstrap/bootstrap.php(244): yii\BaseYii::createObject(Array)
#15 /path/to/craft/vendor/craftcms/cms/bootstrap/console.php(34): require('/Volumes/BLUE/P...')
#16 /path/to/craft/craft(21): require('/Volumes/BLUE/P...')
#17 {main}

To Reproduce Steps to reproduce the behavior:

  1. Local serve (./craft serve)
  2. Go on Plugin Store, install the plugin
  3. Works fine (at least for now)
  4. Stop the server (Ctrl+C)
  5. Restart the server (./craft serve)
  6. Get this error. Did not serve...

Expected behavior Craft running on serve.

Desktop (please complete the following information):

rtrudel commented 5 years ago

I may have found the problem:

I replaced: Craft::$app->on(Application::EVENT_INIT, function (Event $event) { with use yii\base\Event; ... Event::on(CraftVariable::class, CraftVariable::EVENT_INIT, function(Event $event) {

I believe it's almost the same but it seems to work.

dustfeather commented 4 years ago

Can be avoided if you enclose the event in something like this: if(Craft::$app instanceof craft\web\Application)