0

When I have create a user via the CLI, I am unable to log into the Magento Admin because there is an error.

Fatal error: Uncaught TypeError: Return value of MSP\TwoFactorAuth\Model\ResourceModel\UserConfig::decodeConfig() must be of the type array, null returned in vendor/msp/twofactorauth/Model/ResourceModel/UserConfig.php on line 96

1 Answer 1

2

This issue is caused by the users encoded_config and encoded_providers being empty. Which in turn can't be unserialized which causes an empty response. The code expects an array.

To resolve this issue.

  1. Make sure you have: cweagans/composer-patches installed. If not this can be installed with composer require cweagans/composer-patches
  2. Add the following in your composer.json
...
"extra": {
    ...
    "composer-exit-on-patch-failure": true,
    "patches": {
        "msp/twofactorauth": {
            "Empty config error": "patches/msp_mfa_no_config_error_fix.patch"
        }
    }
},
  1. make the following file: patches/msp_mfa_no_config_error_fix.patch
--- Model/ResourceModel/UserConfig.php    2020-06-19 11:30:47.611900565 +0000
+++ Model/ResourceModel/UserConfig.php 2020-06-19 11:38:47.911245449 +0000
@@ -99,18 +99,26 @@
   public function _afterLoad(AbstractModel $object)
   {
       parent::_afterLoad($object);
-
-        try {
-            $object->setData('config', $this->decodeConfig($object->getData('encoded_config') ?? ''));
-        } catch (Exception $e) {
-            $object->setData('config', []);
-        }
-
-        try {
-            $object->setData('providers', $this->serializer->unserialize($object->getData('encoded_providers') ?? ''));
-        } catch (Exception $e) {
-            $object->setData('providers', []);
+        
+        $config = [];
+        if($object->hasData('encoded_config')){
+               try{
+                       $config = $this->decodeConfig($object->getData('encoded_config') ?? '');
+               } catch (Exception $e) {
+                       // don't need to do anything should fall back to empty []
+               }
       }
+        $object->setData('config', $config);
+        
+        $providers = [];
+        if($object->hasData('encoded_providers')){
+            try {
+                $providers = $this->serializer->unserialize($object->getData('encoded_providers') ?? '');
+            } catch (Exception $e) {
+                // don't need to do anything should fall back to empty []
+            }
+        }
+        $object->setData('providers', $providers);

       return $this;
   }

  1. composer update
  2. rm -rf vendor/msp/twofactorauth
  3. composer install --no-dev

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.