When dealing with Authentication in Laravel, there are several options out of the box. This tutorial will look at how we can add a one-time password approach to our authentication flow.

declare(strict_types=1); namespace Domains\Auth\DataObjects; use Domains\Auth\Enums\Type; use JustSteveKing\DataObjects\Contracts\DataObjectContract; final class User implements DataObjectContract { public function __construct( private readonly string $email, private readonly Type $type, ) {} public function toArray(): array { return [ 'email' => $this->email, 'type' => $this->type, ]; }}

RateLimiter::clear( key: $this->getRateLimitKey( method: $method, ), ); } protected function getRateLimitKey(null|string $method = null): string { if (! $method) { $method = debug_backtrace()['function']; } return strval(static::class.

Auth::loginUsingId( id: intval($command->handle( email: $this->email, )->getKey()), ); return redirect()->route( route: 'app:dashboard:show', ); } protected function forgetOtp(): void { Cache::forget( key: "{$this->ip}-one-time-password", ); } public function rules(): array { return [ 'email' => [ 'required', 'string', 'email', ], 'otp' => [ 'required', 'string', 'min:6', ]]; } public function render(): ViewContract { return View::make( view: 'livewire.auth.one-time-password-form', ); }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners