Skip to content

Commit 16df965

Browse files
authored
Update README.md
1 parent d8ff77e commit 16df965

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,31 @@ Switch between templates in `config/otpz.php`:
301301

302302
### Custom User Resolution
303303

304-
By default, OTPz creates new users when an email doesn't exist. Customize this behavior:
304+
By default, OTPz creates new users when an email doesn't exist. You can customize this behavior by creating your own user resolver and registering it in the config. In this example we throw a validation error if a user with the given email address does not exist.
305305

306306
```php
307-
// Create your own resolver
308307
namespace App\Actions;
309308

310-
use BenBjurstrom\Otpz\Contracts\UserResolver;
309+
use App\Models\User;
310+
use BenBjurstrom\Otpz\Models\Concerns\Otpable;
311+
use Illuminate\Validation\ValidationException;
311312

312-
class MyUserResolver implements UserResolver
313+
/**
314+
* @method static Otpable run(string $email)
315+
*/
316+
class MyUserResolver
313317
{
314-
public function resolve(string $email): ?\Illuminate\Contracts\Auth\Authenticatable
318+
public function handle(string $email): Otpable
315319
{
316-
// Your custom logic
317-
return User::where('email', $email)->firstOrFail();
320+
$user = User::where('email', $email)->first();
321+
322+
if($user){
323+
return $user;
324+
}
325+
326+
throw ValidationException::withMessages([
327+
'email' => 'No user found with that email address.',
328+
]);
318329
}
319330
}
320331
```

0 commit comments

Comments
 (0)