laravel-mongodb: Password Reset errors [1 fix/other open]

I just started working with this package, not disappointed so far. However when enabling the PasswordResetServiceProvider I encountered an error when requesting a new password.

In the file Jenssegers/Mongodb/Auth/PasswordBrokerManager.php the method createTokenRepository creates an instance of the DatabaseTokenRepository. However the second argument should be a hash. I copied te code form the original method so the function looks like this:

protected function createTokenRepository(array $config)
    {
        $key = $this->app['config']['app.key'];

        if (Str::startsWith($key, 'base64:')) {
            $key = base64_decode(substr($key, 7));
        }

        $connection = isset($config['connection']) ? $config['connection'] : null;

        return new DatabaseTokenRepository(
            $this->app['db']->connection($connection),
            $this->app['hash'],
            $config['table'],
            $key,
            $config['expire']
        );

I tried it and it send the mail as expected.

Also when you have received the password reset email. When you have entered your email and new password a new error occurs.

FatalThrowableError in DatabaseTokenRepository.php line 24: Cannot use object of type MongoDB\BSON\UTCDateTime as array

I think this is because the tokeExpired method expects and $createdAt parameter and receives a $token parameter. I can only assume that those two mean different things.

I used Laravel 5.4.23 when debugging this problem.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (1 by maintainers)

Commits related to this issue

Most upvoted comments

The composer.json after a fresh install has a part that looks exactly like this

...
"psr-4": {
    "App\\": "app/"
}
...

Just change it to this

...
"psr-4": {
    "App\\": "app/",
    "Jenssegers\\Mongodb\\": "fixes/Jenssegers/Mongodb/"
}
...

In the same directory as composer.json create a new directory called fixes. If you want to change Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php, then create the directories and the file such that you will have fixes/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php. Then delete the composer.lock file and install composer again.

The namespaces will still remain the same. How the autoload will work it will prioritize the fixes over the package files/classes.

Update: Don’t reïnstall Composer or delete composer.lock. Instead use the rebuild command, this will only rebuild the autoloader.

For the token invalid I found that you also need to change getPayload method from the DatabaseTokenRepository to

protected function getPayload($email, $token)
    {
        return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new UTCDateTime(time() * 1000)];
    }

Yeah, you don’t have to, but I it is better to keep to the original code in case you miss something.

There is a way, but it is kind of a hacky way. Create a map called fixes and then add in the composer.json file in the psr-4 array a entry called "Jenssegers\\Mongodb\\": "fixes/Jenssegers/Mongodb/". Then take the files you want to replace like the DatabaseTokenRepository.php and add it to fixed/Jenssegers/Mongodb/Auth/DatabaseTokeRepository.php. Then you have to reset composer, by deleting composer.lock and install composer again. And it should work.

Any update on this issue?

Please Reopen the issue as there is no commit resolve it yet