codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
350 stars 123 forks source link

Bug: "Call to a member function createIdentity() on null" during 2FA for 'Register' #737

Closed projectwehelp closed 1 year ago

projectwehelp commented 1 year ago

PHP Version

8.1.8

CodeIgniter4 Version

4.3.4

Shield Version

v1.0.0-beta.6

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

10.6.12-MariaDB-0ubuntu0.22.04.1

Did you customize Shield?

no

What happened?

Enable Two-Factor Authentication for 'Register' making the following changes in App/Config/Auth.php

  public array $actions = [
        'register' => '\CodeIgniter\Shield\Authentication\Actions\EmailActivator::class',
        'login'    => null,
    ];

But when attempting to do a test registration get the following error message:

Error
Call to a member function createIdentity() on null
VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php at li

Steps to Reproduce

Standard 6 step install as per install guide in github.

Standard default register, login , logout working fine out of box.

On making the changes on App/Config/Auth.php to Enable Two-Factor Authentication for 'Register':

 public array $actions = [
        'register' => '\CodeIgniter\Shield\Authentication\Actions\EmailActivator::class',
        'login'    => null,
    ];

After that attempting to do a test registration get the following error message:

Error
Call to a member function createIdentity() on null
VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php at line 202

Log files says:

CRITICAL - 2023-05-12 07:03:29 --> Call to a member function createIdentity() on null
in VENDORPATH/codeigniter4/shield/src/Authentication/Authenticators/Session.php on line 202.
 1 VENDORPATH/codeigniter4/shield/src/Controllers/RegisterController.php(137): CodeIgniter\Shield\Authentication\Authenticators\Session->startUpAction()
 2 SYSTEMPATH/CodeIgniter.php(934): CodeIgniter\Shield\Controllers\RegisterController->registerAction()
 3 SYSTEMPATH/CodeIgniter.php(499): CodeIgniter\CodeIgniter->runController()
 4 SYSTEMPATH/CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest()
 5 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()

Expected Output

It should have worked and sent the 2FA email to complete the Registration.

Anything else?

Also, the new accounts get registered and but login using the new accounts says user not activated.

datamweb commented 1 year ago

Hello @projectwehelp, thanks for the report.

This is not a bug, please adjust as below.

public array $actions = [
'register' => \CodeIgniter\Shield\Authentication\Actions\EmailActivator::class,
'login'    => null,
];
projectwehelp commented 1 year ago

Yes, it is working now! the quotes were getting in the way.

Appreciate the quick response & solution!