Sometimes we don’t want users to have passwords. Sometimes we want to send a magic link to a user’s email address and have them click to gain access.
While we are at it, we can remove the password resets table, as we will not have a password to reset.
final class LoginForm extends Component { public string $email = ''; public string $status = ''; public function submit(SendLoginLink $action): void { $this->validate(); $action->handle( email: $this->email, ); $this->status = 'An email has been sent for you to log in. '; } public function rules(): array { return [ 'email' => [ 'required', 'email', Rule::exists( table: 'users', column: 'email', ), ]]; } public function render(): View { return view('livewire.auth.login-form'); }}
final class SendLoginLink { public function handle(string $email): void { Mail::to( users: $email, )->send( mailable: new LoginLink( url: URL::temporarySignedRoute( name: 'login:store', parameters: [ 'email' => $email, ], expiration: 3600, ), )); }}