cms
cms copied to clipboard
Eloquent driver is always used in the activation/reset password flow
Bug Description
When I try to reset a password from the CP (via Forgot password) I get this exception just after submit the form:
BadMethodCallException
Call to undefined method App\Models\User::email()
I'm on an existing Laravel app and I've two differents guards, one for Laravel users and one for statamic users. Statamic users are stored with the file driver.
I can send the activation/reset password email if I create a new user or if I click on "Send reset password email" from the CP user management. But when I go to the reset password form then type my email and new password then submit, A validation error says "The email address doesn't exists".
It seems Statamic try to use the Eloquent driver at some places of the activation/reset password flow.
How to reproduce
- Create a fresh Laravel app
- Install statamic via composer
- Create an additional auth guard with the statamic provider (see Extra Detail section).
- Configure statamic users storage driver as
fileand noteloquent
Extra Detail
Here is the content of my config/auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'statamic_users' => [
'driver' => 'statamic',
],
],
// ...
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'statamic' => [
'driver' => 'session',
'provider' => 'statamic_users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
And here my config/statamic/users.php
'repository' => 'file',
'repositories' => [
'file' => [
'driver' => 'file',
'paths' => [
'users' => base_path('users'),
'roles' => resource_path('users/roles.yaml'),
'groups' => resource_path('users/groups.yaml'),
],
],
],
// ....
'guards' => [
'cp' => 'statamic',
'web' => 'web',
],
// ...
Environment
Statamic 3.1.18 Pro Laravel 8.34.0 PHP 7.4.3 aryehraber/statamic-font-awesome 2.2.0 edalzell/blade-directives 3.1
Statamic has been Installed on an existing Laravel App via composer
I experience the same problem. It does work when the user in question has super: true set, though. Any other users don't work. Weird bug. I also use a Pro licence (purchased, not just for testing), so there should be no issue with "One (super) admin user account".
Yeah, we've just run into this on a project as well. If I have some time this weekend, I'll take a look at fixing it (if no one beats me to it).
@duncanmcclean Have you had a chance to check this out yet?
I haven't had any time, sorry!
Just ran into the same trouble. Followed this guide: https://statamic.dev/tips/using-an-independent-authentication-guard
Looks like it's just a case of adding an additional password reset config in config/auth.php Example:
'passwords' => [
'resets' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'activations' => [
'provider' => 'users',
'table' => 'password_activations',
'expire' => 4320,
'throttle' => 60,
],
'resets_statamic' => [
'provider' => 'statamic',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'activations_statamic' => [
'provider' => 'statamic',
'table' => 'password_activations',
'expire' => 4320,
'throttle' => 60,
],
],
And then updating the brokers in config/statamic/users.php
'passwords' => [
'resets' => 'resets_statamic',
'activations' => 'activations_statamic',
],
If this is the way to go then it would be good to get these docs updated. I've added an issue on Statamic docs: https://github.com/statamic/docs/issues/910