componist/auth
Livewire-basiertes Auth-Package für Laravel mit fertigen UI-Komponenten für Login, Registrierung, Passwort-Reset und E-Mail-Verifizierung sowie optionaler E-Mail-2FA. Inklusive Rate-Limiting, Session-Härtung, Feature-Flags und konfigurierbarer Defaults.
Installation
composer require componist/auth
php artisan vendor:publish --tag=componist.auth.publish.config
php artisan migrate
User Model Update
Extend your User model with the required trait and interface:
use Componist\Auth\Traits\AddComponistAuthentication;
use Componist\Auth\Contracts\TwoFactorAuthenticatable;
class User extends Authenticatable implements TwoFactorAuthenticatable
{
use AddComponistAuthentication;
// ...
}
First Use Case Add the Livewire component to your login view:
<x-componist-auth::login />
The package provides pre-built UI for:
login)register)password-reset)verify-email)two-factor-setup)config/componist_auth.php (published via vendor:publish).resources/views/vendor/componist-auth/ (customizable Blade templates).app/Http/Livewire/ (generated by the package).app/Http/Middleware/ (check for Componist\Auth\Http\Middleware\*).Authentication Flow
<x-componist-auth::login /> for login with built-in rate limiting.php artisan make:livewire CustomLogin extends Componist\Auth\Livewire\Login
Override methods like rules() or messages() in the new class.Registration with 2FA
'features' => ['two_factor' => true]).Password Reset
<x-componist-auth::password-reset />.php artisan vendor:publish --tag=componist.auth.publish.views
Email Verification
MustVerifyEmail trait in your User model.<x-componist-auth::verify-email /> for the verification UI.Session Hardening
Componist\Auth\Http\Middleware\EnsureEmailIsVerified or Componist\Auth\Http\Middleware\CheckTwoFactor).app/Http/Kernel.php:
'web' => [
\Componist\Auth\Http\Middleware\EnsureEmailIsVerified::class,
// ...
],
'features' => ['registration' => false] to disable registration).protected function rules()
{
return array_merge(parent::rules(), [
'custom_field' => 'required|string',
]);
}
php artisan vendor:publish --tag=componist.auth.publish.lang
Override translations in resources/lang/.$this->actingAs($user)->login(); // Custom helper (if provided)
$this->actingAs($user)->verifyEmail();
Migration Conflicts
two_factor_code, two_factor_expires_at, last_login) to the users table.php artisan migrate --pretend first to check for conflicts, or manually merge migrations if needed.Caching Issues
Componist\Auth\Livewire\* classes are not autoloaded.php artisan config:clear
php artisan view:clear
2FA Session Expiry
two_factor_expires_at field uses a TTL (Time-To-Live) for 2FA codes.$user->generateTwoFactorCode();
Middleware Order
EnsureEmailIsVerified and CheckTwoFactor middleware are placed after auth middleware in Kernel.php:
'web' => [
\Illuminate\Auth\Middleware\Authenticate::class,
\Componist\Auth\Http\Middleware\EnsureEmailIsVerified::class,
\Componist\Auth\Http\Middleware\CheckTwoFactor::class,
],
Livewire Errors
storage/logs/livewire.log.config/componist_auth.php:
'debug' => env('APP_DEBUG', false),
Rate Limiting
config/componist_auth.php under rate_limits.Email Verification Tokens
personal_access_tokens table. If verification fails:
$user->sendEmailVerificationNotification();
verified_at column in the users table.Custom Livewire Components
Login, Register) to add custom logic:
php artisan make:livewire CustomRegister extends Componist\Auth\Livewire\Register
updated(), rules(), or messages().Custom Views
php artisan vendor:publish --tag=componist.auth.publish.views
resources/views/vendor/componist-auth/.Custom Notifications
VerifyEmail, ResetPassword) by binding your own:
use Componist\Auth\Notifications\VerifyEmail as ComponistVerifyEmail;
class VerifyEmail extends ComponistVerifyEmail
{
public function toMail($notifiable)
{
// Customize email content
return (new MailMessage)
->subject('Custom Verification Subject')
->line('Custom verification line.');
}
}
AuthServiceProvider:
public function boot()
{
$this->app->bind(
\Illuminate\Auth\Notifications\VerifyEmail::class,
CustomVerifyEmail::class
);
}
Feature Flag Logic
if (config('componist_auth.features.registration')) {
// Enable registration logic
}
Session Hardening
config/componist_auth.php:
'session' => [
'secure' => env('SESSION_SECURE_COOKIE', true),
'http_only' => true,
'same_site' => 'lax',
],
How can I help you explore Laravel packages today?